Dynamic Attachment based on choices

harshi_ramesh
Tera Expert

Hello people

I have a requirement to show 'Downloadable' template file under a field on a catalog form. The catch is, this file will change based on the selection or combination of selections made on two fields of type 'SelectBox'.
Variable1 has 4 choices, Variable2 has1 choices.
Example Scenario:
Variable1 -> Option A selected
Variable2 -> Option 1 selected.

So, on basis of this, respective file template should be shown under 'Upload Template'(Type is attachment). User can click on the template and get the template downloaded.

Unser Annotation of 'Upload Template' we have 'Insert/edit Link' but it remains static. We need the link to change.

I tried few ways but nothing seems to work as required. 
Any idea on how to crack this? Would be helpful! 🙂

Appreciate your time and effort.

Thanks

1 ACCEPTED SOLUTION

kaushal_snow
Mega Sage

@harshi_ramesh ,

 

I have worked on this scenario in the past, you can implement dynamic attachments in your catalog item by using a Rich Text / HTML variable (or custom widget variable) whose content (an <a> download link pointing to a sys_attachment.do?sys_id=…) gets set via a client script triggered by changes in your select boxes, with the sys_id value returned from a GlideAjax/Script Include that queries the sys_attachment table based on those field values......

 

If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/

View solution in original post

6 REPLIES 6

Brad Bowman
Kilo Patron
Kilo Patron

I'm not following why you have an attachment type variable if a file will not be attached to the request - you could try using a label.  In any case, I would create a variable for each file template.  Use an onChange Catalog Client script when variable 1 changes to determine which variable is displayed.  Once that's working, copy it to do the same when variable 2 changes - unless this variable will always only have 1 choice, then it's not really needed.

Ankur Bawiskar
Tera Patron
Tera Patron

@harshi_ramesh 

I agree with what @Brad Bowman  to use different Rich Text Label variable which shows the different file

then based on change of variable value show/hide the variable

OR

You can use a variable of type Custom and include Widget to it.

widget will detect onChange event of variable and based on choices will show that HTML element with the link

see this links for reference help

ServiceNow Code Snippets: Catalog Items and the Portal Widget Data Object 

How to pass a value from a Widget to a Catalog item variable 

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@harshi_ramesh 

Did you get a chance to check my above solution?

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

kaushal_snow
Mega Sage

@harshi_ramesh ,

 

I have worked on this scenario in the past, you can implement dynamic attachments in your catalog item by using a Rich Text / HTML variable (or custom widget variable) whose content (an <a> download link pointing to a sys_attachment.do?sys_id=…) gets set via a client script triggered by changes in your select boxes, with the sys_id value returned from a GlideAjax/Script Include that queries the sys_attachment table based on those field values......

 

If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/