How to validate if a specific file(e.g. User.xlsx) is attached while creating a catalog item?

Vidya Sagar Mis
Tera Contributor

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.

 

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

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

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

Ahmmed Ali
Mega Sage

try

 //for testing script, i created on change. you can use the statement in your script

find_real_file.png

 

find_real_file.png

 

find_real_file.png

 

Thanks,

Ali

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

SANJEEV4
Tera Contributor

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