Dynamic attachment on Catalog Item from a record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2022 04:42 AM
Hello Community,
a client has a specific requirement to attach a file from a record to a catalog item.
The way it's supposed to work is that there is a UI Action that redirects you to the catalog item and when you get there, the attachment from the record is supposed to be there.
The cat. item has a reference field to the record but I just don't know how to do it since the cat. item is not a created record yet so GlideSysAttachment.copy will probably not work.
Is there a way to do it dynamically like that?
Thanks
Patrik
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2022 05:46 AM
Hi Patrik,
Would you please explain a bit from which records you want to copy attachment?
Thanks,
Sagar Pagar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2023 10:41 AM
Was any solution found for this request?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2024 06:04 AM
Hi @Patrik Z ,
from the UI Action you could redirect to the catalog item page and add to the url a parameter, for example the sys_id of the attachment you want to be in the catalog item.
Then, with an onLoad script you could retrieve that parameter from the URL and set it to a variable of type Attachment (it will take the sys_id of an attachment as value). In this way you could set a dynamic attachment on the catalog item.
Here's an example of the Catalog Item onLoad script:
function onLoad() {
//Pre-load values from URL if available
var url = top.location.href;
var attachmentSysId = new URLSearchParams(url).get("sysparm_att");
if (attachmentSysId) {
g_form.setValue('var_myattachment', attachmentSysId);
}
}
Here, var_myattachment is your attachment type variable on catalog item, and sysparm_att is the parameter you need to pass in the URL; so the URL would be like this: "https://myinstance.service-now.com/sp?id=sc_cat_item&sys_id=XXXXXXXXXX&sysparm_att=abcdef1234567890".
Let me know if this helped!
Regards
Simone