- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2014 02:59 PM
Is there a way to check for attachments in the current form and making attachment mandatory if a field is checked ?
Solved! Go to Solution.
- Labels:
-
Service Mapping

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2014 10:59 AM
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;
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2014 10:59 AM
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;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2014 11:09 AM
Hi Pradeep, this seems to work, but it's showing an alert even though a file has been attached to the form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2014 11:11 AM
I was pointing to the wrong table that seems to work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2015 07:38 PM
Hi Pradeep,
The script you provided helped me make attachments mandatory on my catalog item. Since I am new to ServiceNow, please excuse my ignorance. Just out of curiosity, I wanted to know if we can use the Gliderecord object in our client scripts? I was of the impression that because Gliderecord is a server side object, it cannot be used in client scripts. But then again, the script you provided ran perfectly fine in a client script. Please help to resolve this dilemma.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2015 10:42 AM
Hi Kunal,
Client side GlideRecord enables the use of some GlideRecord functionality inside client scripts. However client script GlideRecord has limited set of functionality.
Hence make sure that query are optimized and they don't run synchronously. The alternative approach is client script + GlideAjax. Please refer the below link for more info.
http://wiki.servicenow.com/index.php?title=GlideAjax
I hope this helps