- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2016 01:51 PM
Hi,
I'm wondering if anyone has successfully implemented functionality that would require an attachment before a field on the form can change. This is not on submission of a catalog item.
Here is our use case:
Legal department puts cases in a 'Pending' state. In order for them to be removed from pending, the user needs to attach a document. It can't be just any document attached either, the user would purposefully need to click a button that said something like "Remove from Pending - Doc Attached" or something.
Thanks in advance for any help or advice!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2016 04:31 PM
Hi Adam,
Here is the script. Just make sure you add a condition as per your req to trigger it. It will be client script.
Script :
function onSubmit() {
var att = new GlideRecord("sys_attachment");
att.addQuery("table_name", "change_request");
att.addQuery("sys_created_by", g_user.userName);
att.addQuery("sys_created_on", '>=', 'javascript:gs.minutesAgo(10)');
att.query();
if (!att.next()) {
alert("Please attach the requested form before submitting.");
return false;
}
return true;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2016 03:29 PM
We have one on a "On Submit" catalog client script:
function onSubmit() {
var cat_id = gel('sysparm_item_guid').value;
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "sc_request");
gr.addQuery("table_sys_id", cat_id);
gr.query();
if (!gr.next()) {
alert("You must attach a file to submit.");
return false;
}
}
In your case I imagine you would want a business rule to enforce it, however. The example above should get you started, let us know if you need additional help.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2016 04:31 PM
Hi Adam,
Here is the script. Just make sure you add a condition as per your req to trigger it. It will be client script.
Script :
function onSubmit() {
var att = new GlideRecord("sys_attachment");
att.addQuery("table_name", "change_request");
att.addQuery("sys_created_by", g_user.userName);
att.addQuery("sys_created_on", '>=', 'javascript:gs.minutesAgo(10)');
att.query();
if (!att.next()) {
alert("Please attach the requested form before submitting.");
return false;
}
return true;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2016 01:34 PM
Pradeep,
I am trying to implement this script in a catalog item so the attachment will be mandatory. It works; however, when I attach a file, I am still prompted. What am I missing?
function onSubmit() {
var cat_id = gel('sysparm_item_guid').value;
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "sc_cat_item");
gr.addQuery("table_sys_id", cat_id);
gr.query();
if (!gr.next()) {
alert("You must attach a file to submit.");
return false;
}
Thanks for your help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2016 01:41 PM
I believe the table you want for a a catalog item is "sc_cart_item".