Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Validate Attachment name on Catalog item.

Abhishek18
Tera Contributor

Hello,

 

I have created a catalog item, and our requirement is, users need to upload 2 mandatory attachments filename1.csv and filename2.csv, If any one of the attachment is not uploaded then alert should populate, 

 

So, I observed that when an attachment is uploaded in service catalog form in Service Portal, an entry is created in sys_attachment table, the table name of the record is "sys_cart_item" and it is populating a table sys_id too. But I'm unable to get the table sys_id from sys_cart_item table.

 

Please suggest me a solution to validate the file names of the attachments being uploaded on catalog form through Service Portal.

 

Thanks

2 REPLIES 2

Mohith Devatte
Tera Sage
Tera Sage

hello @Abhishek18 ,

you can have a look at this article where it gave two scripts one for native and portal view .

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0725744

YOU CAN DO A GLIDE RECORD TO SYS_ATTACHMENT TABLE LIKE IT IS MENTIONED IN ARTICLE 

but once you do the glide record you can get the file name and validate like below 

var grAttach = new GlideRecord("sys_attachment");
grAttach.addQuery("table_name", "sp_portal");
grAttach.addQuery('sys_created_by', g_user.userName);
grAttach.addQuery("table_sys_id", <sys_id_of_catalog_item>);
grAttach.query();
if(grAttach.next())
{
if(gr.file_name=="your_file_name")
{
return false;
}
}

Hope this helps 

Mark my answer correct if this helps you

Abhishek18
Tera Contributor

Hi @Mohith Devatte 

 

Whenever I upload an attachment in service catalog in portal, no entries are created in sys_attachment table with table name "sp_portal", it is only creating an entry with "sys_cart_item", and I could see there is no record present with table sys_id in sys_cart_item table.