Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Adding attachment button to service catalog request

Jan-Z
Giga Expert

I have created a service catalog item which requires documents to be attached to the request before the request can be submitted. The team working with this request does not like the paperclip icon and they would like a "button" but in the middle of the service catalog item below an already created label. They want the "button" because they feel it will be more visible to end users submitting requests.

To accomplish this I created a variable macro with label and used the macro add_attachment. This looks correct and provide the look the end users want BUT
it does not work. Upon testing I can add attachments using this button and the attachments appear at the top of the request as attachments under manage attachments. BUT upon submission the attachments disappear. When I look at the submitted request there are no attachments, when I look at the SC item there are no attachments.

Does anyone know how to add an attachments 'BUTTON" to an SC request? Or to fix the issue I am having using the macro with label? Any help would be appreciated. Thanks.

1 ACCEPTED SOLUTION

1. Create UI Macro
1a. In the "Type Filter Text" search for UI Macro
1b. Create New:
1c. Paste the following code:



<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<b>Use the paperclip</b>
<a onclick="saveCatAttachment(gel('sysparm_item_guid').value, 'sc_cart_item')">
<img title="Attachments..." height="16" src="images/icons/attachment.gifx" border="0" width="16"/></a>
<b>to attach items to this request.</b>
</j:jelly>

2. Add a Variable to your Catalog Item.
3. Type-- UI Macro
4. Choose your newly created macro in step 1.
5. It should show up on your form (see attachment) it is clickable and functions just as the OOB paperclip icon on the top right of forms.
6. If you want change two attributes in the code above
6a. Change the icon by uploading an icon or choosing one from the image browser (src="images/icons/attachment.gifx" or src="images/pdf.gifx")
6b. Change the size of the icon (height="16" or height="25")

Try out your UI macro.


View solution in original post

40 REPLIES 40

NM. Found the fix: https://community.servicenow.com/people/MB/blog/2012/01/11/2480



Needed to add a Read and Write ACL to the to sc_cart_item table per the instructions at the bottom of that blog.




Note, have not tested on Fuji, we're are still using Eureka


The fix in the article linked above survived a eureka to fuji upgrade.


carlos_monchuch
Giga Contributor

Hi all



Has anyone noticed that this does not now work in Fuji???



No pop up when clicking on icon?


I definitely think something has changed with Fuji.



We have a record producer for HR Case table and to help users with attaching files, we added a Macro variable that calls the function to attach and you can see the file added to the record producer.



What we're not seeing is the file attached to the HR Case record. Not sure why.



Oddly enough, if you drag and drop an attachment to the record producer, the file does get attached to the Case record.



Add two files, one from each method, and only the drag and drop one makes it to the Case record, even though they both show as being attached to the producer.



Anyone with thoughts on this?


Dennis, I was also having this issue with Fuji and HR cases specifically.     I created a macro and used the following code:



<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">  


      <button id="custom_add_attachment" type="button" onclick="saveCatAttachment(gel('sysparm_item_guid').value, '$[item_table]')" class="icon-button icon-paperclip" title="Add attachments..."><b>Click here to add attachments...</b></button>  


</j:jelly>