Scriptable Order Guide - The order guide resulted in no items being selected for order
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2022 03:07 AM
Hi Community,
I have an After Insert Business Rule on the User table which needs to automatically submit an order guide along with a catalog item in its Rule Base. I referred this article and wrote the below script:
(function executeRule(current, previous /*null when async*/ ) {
// Define Json variable with required information and assign values to Order Guide variables
var json = {
"opened_by": current.manager,
"requested_for": current.getUniqueValue(),
"department": current.department,
"remote": "No",
"standard_package": "No",
// define catalog items under rule base and assign values to respective variables of the item.
"items": [{
"sys_id": "1f1c21aa1b45d550e8d9bb751a4bcb14",
"variables": {
"device_type": "Standard Laptop",
"additional_monitors_required": "false"
},
"sysparm_quantity": "1"
}]
};
// Customise the below script as per your order guide details
var gr = new GlideRecord("sc_cat_item_guide");
if (gr.get("name", "New Hire Request")) {
var sog = new SNC.ScriptableOrderGuide(gr.getValue("sys_id"));
var result = sog.process(new JSON().encode(json));
if (!result)
gs.addInfoMessage('Request was not created');
else {
var request = sog.getRequest();
gs.addInfoMessage('Request has been created for ordergude' + ' ' + request.number);
}
}
})(current, previous);
When I create a new user, I get the message "The order guide resulted in no items being selected for order.". I also referred the docs (Running order guides automatically (servicenow.com)) but I don't clearly understand. Please give suggestions. Thanks in advance
- Labels:
-
Request Management
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2022 09:56 PM
When ordering a order guide through scripts it automatically submits all catalog items under its rule base. You cannot specify only one item with script. You would need to create some variables on the order guide level and then through the Rule base Item Variable assignments bind those OG variables down to the Catalog item. And ofcourse populate the OG variables via script in your JSON
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2022 03:35 AM
Thanks for the response Harun. I modified the my script to run the OOTB New Hire Order Guide. It is creating a request along with request items based on the Rule Base but the values to the questions are not set on the requested items as given in the script. I think it might have to do with JSON formatting for the items. Here's my script:
(function executeRule(current, previous /*null when async*/ ) {
// Define Json variable with required information and assign values to Order Guide variables
var man = current.manager.toString();
gs.addInfoMessage('Manager sys id ' + man);
var nh = current.getUniqueValue();
var depmt = current.department.toString();
gs.addInfoMessage('Department sys id ' + depmt);
var em = current.email;
gs.addInfoMessage('New Hire Email ' + em);
var json = {
"opened_by": man,
"requested_for": nh,
"department": depmt,
"remote": "No",
"standard_package": "No",
// define catalog items under rule base and assign values to respective variables of the item.
"items": [{
"sys_id": "04b7e94b4f7b4200086eeed18110c7fd",
"variables": {
"acrobat": "true",
"Additional_software_requirements": "MS Office 2007"
},
}, //Standard Laptop
{
"sys_id": "186d917a6fab7980575967ddbb3ee4f2",
"variables": {
"new_email": "true"
}
}, //New Email Account
{
"sys_id": "8b3ae7fedc1be1004ece5c08239e522b",
}, //Corp VPN
{
"sys_id": "962967674ff38200086eeed18110c7e7",
} //Desk Set Up
],
};
// Customise the below script as per your order guide details
var gr = new GlideRecord("sc_cat_item_guide");
if (gr.get("name", "New Hire")) {
var sog = new SNC.ScriptableOrderGuide(gr.getValue("sys_id"));
var result = sog.process(new global.JSON().encode(json));
if (!result)
gs.addInfoMessage('Request was not created');
else {
var request = sog.getRequest();
gs.addInfoMessage('Request has been created for order Guide' + ' ' + request.number);
}
}
})(current, previous);
Any help appreciated. Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2025 04:38 AM
Hi Adarsh,
Did you get solution for the above query?