Mandatory Attachments Order Guide and Catalog Items sharing solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2013 08:26 AM
To start I'm pretty new to ServiceNow. Only been working with it for about 3 months.
I had some requests to make attachments mandatory on catalog items.
When I added that request to an order guide it broke and wouldn't check for an attachment or submit.
I tried many different options and variations and finally go one to work and just wanted to share the solution that works.
I used the many articles on the forums for this solution. 🙂 So i have to say thank you to everyone.
The pieces:
On your catalog item (Requests or Record Producers)
After all your other variables create on called "u_order_guide" or whatever you wish (but make sure you modify all to match)
This variable must be a Yes/No and have the default value set to No.
Create a UI Policy that hides this variable onLoad.
Create a client script as follows:
/*
For the Client Script on the request item/Record Producer
Name: Mandatory Attachments
Applies to: A Catalog Item
Type: OnSubmit
*/
function onSubmit() {
if (g_form.getValue('u_order_guide') == 'Yes') {
var ord_id = gel('sysparm_cart_edit').value;
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "sc_cart_item");
gr.addQuery("table_sys_id", ord_id);
gr.query();
if (!gr.next()) {
alert("You must attach a file to submit.");
return false;
}
}
else if (g_form.getValue('u_order_guide') == 'No') {
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;
}
}
}
Then on your Order Guide:
Make sure that Cascading Variables is checked or this will not work.
Create the same exact variable after all your other variables called "u_order_guide" and make it a Yes/No but make the default value be 'Yes'
Then create a Catalog Client Script as follows:
/*
For the Catalog Client Script that applies to the Order Guide
Name: Hide Order Guide Variable
Applies to: A Catalog Item
Type: OnLoad
Catalog Item: YOUR ORDER GUIDE
Applies on: check all boxes you need
*/
function onLoad() {
var item = $("current_item");
var guide = $("sysparm_guide");
if (item != null && guide != null && item.value == guide.value)
g_form.setDisplay('u_order_guide', false);
}
If you have any suggestions or comments I am happy to refine my work.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2015 01:48 AM
Thank you so much for sharing! We just upgraded to Fuji and are very happy to find a solution to this question!
I only had a little issue with line 22 var gr = new GlideRecord("sys_attachment");
SN was complaining that the variable already existed; so on line 10 we added: var gr ;
and now everything is working perfect!
Again, thanks!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2015 12:48 AM
I am working on order guide. I have to check whether the user has attached the attachment.I tried with the onsubmit script without creating the 'u_order_guide' variable. I am able to get the warning message to attach document.I will not be able to checkout without attaching the document. But after checking out, if I try to edit my item in shopping cart and click 'update cart', the changes made to the item are not getting captured and I am not rediredted to the Shopping cart page. I get an error message stating "Uncaught TypeError Cannot read property 'value' of null". Please give me a solution for this if you have encountered the same issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2016 07:05 AM
Hello Divya,
Yes that was the issue was facing when I first built this solution. It would get an error and not work correctly. That is why the 'u_order_guide' variable is important. It does not work correctly without it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2017 08:28 AM
What if you just need this for a simple service catalog item (requesting an account for example) and not using an order guide? Customer wants to make the attachment mandatory for a particular service catalog item.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2017 08:29 AM
I think I got my answer here: Re: Check Attachments on current form.
Crossing my fingers it works!
LIsa