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

Hello,



After submitting the request,unable to see the attachement in Service Cataloge.



Thanks


Lalit Gupta


i had the same problem...



Go to System UI> UI Macros > New  



-------------------------------------------------


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


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


 


<g:evaluate>  


var rprf = RP.getReferringURL();  


var og = rprf.indexOf('sysparm_guide') >= 0;  


</g:evaluate>  


 


<j:if test="${og}">  


<div id="order_guide_item_attachment">  


<div id="header_attachment" style="display: block; width: 100%; overflow: hidden;">  


<div id="header_attachment_size_checker">  


<ul id="header_attachment_list">  


<li>  


<a id="header_attachment_list_link" href='#' class="attachment" onclick="saveCatAttachment(gel('sysparm_cart_edit').value, 'sc_cart_item'); return false;">  


                                                                <img title="Attachments..." src="images/icons/attachment.gifx" height="16" border="0" width="16" /> $[sp]  


                ${gs.getMessage('Please add your attachment')} (<span class="attachmentNumber"></span>):  


</a>  


</li>  


<script>  


updateAttachmentCount(gel('sysparm_cart_edit').value);  


if($('header_attachment'))  


$('header_attachment').style.height = '20px';  


</script>  


 


                  </ul>  


                  </div>  


</div>  


</div>  


</j:if>  


 


<script>  


//This initializes the default action. Do you want attachments to be displayed or not onload.   To show, change the .show() to .hide()  


$('order_guide_item_attachment').show();  


</script>  


</j:jelly>  


Steven,



I found this code from here. MB's Blog


I am using record producer to allow users to fill a form with attachments. Since the form is long, I wanted users to see the attachment where they are calling the macro so they do not have to be confused not knowing that the attachments are listed on the top of the form. If I copy this code in my ui macro, the link does not show up, but


the following code work. A couple of questions:


1. How can I make the attachment file number updated here as soon as files attached.


2. Due to file attachment is a mandatory field, I made this macro variable mandatory. I would like to find a way to make the variable not mandatory as soon as a file is attached. Not sure how to mark this variable not mandatory from this ui macro.



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


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


<div id="header_attachment" style="display: block; width: 100%; overflow: hidden;">



<li>


<a id="header_attachment_list_link" href='#' class="attachment" onclick="saveCatAttachment(gel('sysparm_item_guid').value, 'u_vendor_information'); return false;">


                                                                <img title="Attachments..." src="images/icons/attachment.gifx" height="16" border="0" width="16" /> $[sp]


                ${gs.getMessage('Manage Attachments')} (<span class="attachmentNumber"></span>):


</a>


</li>    



<script>


updateAttachmentCount(gel('sysparm_item_guid').value);


if($('header_attachment'))


$('header_attachment').style.height = '20px';


</script>



</div>


</j:jelly>


Hello,



And thank you for these examples. I have one question still, since I'd like to add that attachment directly to a Change Request that is created by using an Order Guide and a Record Producer.



So, how to figure out the sys_id of a Change Request that is created this way?



Br,


--Mikko


I also need some help with this one. Using the UI Macro on a request item I can see that it attaches and I can see it in sys_attachment. However my request is a record producer for the change_request table. I need it to show up on the created change request. Can anybody give me a nudge?