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
‎06-21-2024 06:28 AM
Can you update this link? Share the page?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2014 05:13 AM
OBTW... thanks a TON for posting this.. by combining his macro and your test code; I am now able to attach documents easily to order guide cart items... AND require the attachment...
you guys ROCK!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2014 05:22 AM
That is very slick for sure! I am glad you found it helpful!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2014 12:47 PM
Very quick fix thanks for your help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2014 08:27 AM
Thanks for this! Easy solution!