Download attachment button on Catalog Item

esha_bhatnagar
Kilo Contributor

Hi Everyone,

I am working on a Catalog Item, I have a Reference Variable wherein I am referencing Applications table, in which all records have two attachments. My requirement is to add two buttons in the Catalog Item, like "Download Attachment 1" and "Download Attachment 2", and when I click on them, the respective attachment gets downloaded.

The attachments vary from record to record, so the attachments referred should be of the particular application which is selected.

Please let me know how can we achieve this?

Thanks,

Esha

4 REPLIES 4

LaurentChicoine
Tera Guru

Hi Esha,



You can create a custom UI Macro which you will include as a variable inside your catalog item. Inside this UI Macro you can add your 2 links/buttons with pure HTML and add dynamic link referencing to your attachments using Jelly script.



Inside your jelly script you can retrieve the sys_id of the catalog item to build your logic using: RP.getParameterValue('sysparm_id')


esha_bhatnagar
Kilo Contributor

Hi Laurent,



Thanks for the reply. I have found the solution for displaying button by using UI Macro in Service Catalog. But its not working in Service Portal. Can you suggest how it can be done? What I have found out from Community posts that Service Portal doesn't support Jelly Script.



Thanks,


Esha


You will have to create a custom service portal widget. A UI macro variable can be linked to both a Ui macro (for service catalog) and to a widget (for service portal) using the widget field.



For the logic of your link, you will have to use service portal utility to retrieve your catalog item sys_id and your the dynamic of your link will be done on the server script of the widget. There is some basic doc on how to build a widget in the servicenow doc if your not sure how it works.


Mihir Mohanta
Kilo Sage

1.Create a macro.Script should be like below just change the instance name and sys_id of the attachment from sys_attachment table.



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


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


<p> <b><font color="red">Please download Form and Attach Updated Form, </font> <a href="https://dev17970.service-now.com/sys_attachment.do?sys_id=1759db12d9259100ee51bc2e07bf0f6b" target ="_blank"><font color="blue">Click Here</font></a><font color="red"> to download form.</font> </b></p>  


</j:jelly>



2.In the catalog create a variable of macro type and refer the macro created in the previous step in this variable.





Thanks,


Mihir