How to validate if a specific file(e.g. User.xlsx) is attached while creating a catalog item?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2018 02:19 AM
I want to validate if a specific file is attached while creating a catalog item. For Example I want to upload a excel file containing list of users and their details on the time of catalog item creation.
For this I have done the following things:
- Created a on-Submit client script which calls a script include to validate the attachment.
- In my script include I am gliding the "sys_attachment" attachment if a file is attached for my catalog item.
The problem is since the catalog item is not created yet..... I am unable to find the sys_id of the record in attachment table(table_sys_id column). But I find that a attachment record got created for each attachment.
Please let me know how can I get the sys_id of the catalog item for which the attachment record got created.
Thanks in advance.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2018 02:44 AM
Hi Sagar,
The attachment is not attached to ritm table but to cart table. use following script and it should work
use this in onSubmit client script
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.addQuery('file_name', 'CONTAINS', '.xlsx');
attachment.query();
if (!attachment.next()) {
alert("Please add the xlsx file as attachment");
return false;
}
return true;
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2018 02:46 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2023 02:37 AM
Hi @Vidya Sagar Mis,
Could you let me know if you found the solution?
I do have the same requirement. Please let me know the solution.
@Ankur Bawiskar var sys_id = gel('sysparm_item_guid').value; - Currently gel is not available. Can you please suggest this
Thanks in advance