Mandatory Attachments Order Guide and Catalog Items sharing solution

jeff_lord
Giga Contributor

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.

20 REPLIES 20

Aaron40
Kilo Guru

Thank you for sharing this. It looks like you went through a bit of work to get this to work on Order Guides as well as forms. Thank you for sharing your solution.


but the attachment icon isn't available on an item in an order guide.. how do they attach anything without getting to the checkout screen and editing the item?


The way we did that is we created a UI Page with a button on it that allows them to attach to the item.


after I posted that i found this article that shows how to add a manage attachment link to any catalog item... the kewl part about it is that it ONLY shows up if the item is in an order guide... you may want to look it is pretty slick



https://community.servicenow.com/people/MB/blog/2012/01/11/2480