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  

Check Attachments on current form.

ankit025
Kilo Contributor

Is there a way to check for attachments in the current form and making attachment mandatory if a field is checked ?

1 ACCEPTED SOLUTION

Hi Ankit Lohani



Try the below script,If you are looking for mandatory attachments on catalog item.


function onSubmit() {


var cat_id = gel('sysparm_item_guid').value;


var gr = new GlideRecord("sys_attachment");


gr.addQuery("table_name", "sc_cart_item");


gr.addQuery("table_sys_id", cat_id);


gr.query();


if (!gr.next()) {


alert("You must attach a file to submit.");


return false;


}


}


View solution in original post

13 REPLIES 13

Would g_form.getParameter("sysparm_item_guid") be a better way to get the guid?   Being that gel is getting the value from the DOM, which we know to avoid wherever possible.   In this case it might not make a difference?


Hi Pradeep



Can you please help with how to check when something is attached to record and when attachment is removed.


I have a requirement to show alert on Knowledge form when something is attached and when something is removed when I save or update record.



Regards,



Waqas


pradeepksharma


Hello Pradeep,


How can it used in Service Portal.Its now working there?



Thank


Saranya


cdgaefke
Kilo Expert

There is a gliderecord routine hasAttachments():



http://wiki.servicenow.com/index.php?title=GlideRecord#hasAttachments



However, as others have alluded to, there are times when you may need to check the attachments table directly.