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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2017 01:58 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2017 06:36 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader