How check attachment name on a catalog item in the Service Portal (SP)?

davide_fais
Tera Expert

Hi ServiceNow Community,

I'd like check attachment name in a catalog client script and manipulate the string, but I don't know how extract attachment name.

How can I do this?

Thanks for your support,

Best Regards.

Davide

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Davide,



First of all you need to query the attachment table in onSubmit catalog client script. But in scoped app you won't be able to use gel() and GlideRecord on attachment table. So you can create onSubmit Catalog Client Script in Global scope and use following script to get attachment name:



var sys_id = gel('sysparm_item_guid').value;
var attachment = new GlideRecord('sys_attachment');

attachment.addQuery('table_name','sc_cart_item');


attachment.addQuery('table_sys_id',sys_id);

attachment.query();  


if (attachment.next()) {

alert("Name of attachment file is:"+gr.file_name);


}



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


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