- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2015 01:24 PM
I'm building a New Hire Order Guide. We're collecting all the information we need to generate the requests on the first screen. Right now, users have to click 'Choose Options', and click on each tab (there are 9 of them), even though they don't need to choose any options, then click Checkout. I'd like them to be able to just answer the questions on the first screen, then click 'Checkout' and get to the order confirmation screen. I'm using Cascading variables from my Order Guide, but 5 of the catalog items have the same variables, so I've created catalog scripts that move the information from the cascaded-to variables that match the Order Guide variables. These don't run unless the tab is clicked on. I've also set 'Ignore Mandatory Evaluation' to True for all of the items, but that doesn't help if the variables aren't getting set correctly without clicking on the tabs.
My users would really like to not see the tabs at all, just click 'Checkout' from the first screen, and go right to the checkout screen.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2015 08:40 AM
I would agree with Abhiram and you can use a catalog item and then you can automatically add other items into the user's cart via client script on the submit of the cart via an AJAX call. Below is some sample code:
On Submit Client Script:
var ajax = new GlideAjax('AJAXAddCatItems');
ajax.addParam('sysparm_name', 'addCatItems');
ajax.addParam('sysparm_variable1', g_form.getValue('variable1'));
ajax.addParam('sysparm_variable2', g_form.getValue('variable2'));
ajax.getXMLWait();
Then create an AJAX script include to add the catalog items. You will notice that I did not use the script in the Wiki article that Abhiram included and that is because calling new Cart() clears the user's existing cart which is not what I wanted. So I took code from the out of the box Script Included named Cart, which is the code that it was calling. Below is example code for your new AJAX Script Include based on the above example
var AJAXAddCatItems = Class.create();
AJAXValidateInstance.prototype = Object.extendsObject(AbstractAjaxProcessor, {
addCatItems: function() {
var scCart = new GlideRecord("sc_cart");
scCart.addQuery("user", gs.getUserID());
scCart.query();
if (scCart.next()) {
var scCartID = scCart.sys_id;
var catItemSysID = 'SYS_ID_OF_CAT_ITEM';
var scCartItem = new GlideRecord("sc_cart_item");
scCartItem.addQuery("cart", scCartID);
scCartItem.addQuery("cat_item", catItemSysID);
scCartItem.query();
if (!scCartItem.next()) {
var variable1 = this.getParameter('sysparm_variable1');
var variable2 = this.getParameter('sysparm_variable2');
var itemID = catItemSysID;
scCartItem.initialize();
scCartItem.cart = scCartID;
scCartItem.cat_item = itemID;
scCartItem.quantity = 1;
var rc = scCartItem.insert();
var ci = GlideappCatalogItem.get(itemID);
var gr = ci.getStandaloneVariables();
var seq = ci.getKeySequence();
while (gr.next()) {
var question = new GlideappQuestion(gr.sys_id);
var variable = new GlideRecord('sc_item_option');
variable.initialize();
variable.item_option_new = gr.sys_id;
var variableValue = "";
var variableName = variable.item_option_new.name.toString();
switch (variableName) {
case 'variable1':
variableValue = variable1;
break;
case 'variable2':
variableValue = variable2;
break;
default:
variableValue = question.getValue();
break;
}
variable.value.setValue(variableValue);
variable.cart_item = rc;
for (var i = 0; i < seq.size(); i++) {
if (seq.get(i) + "" == gr.sys_id + "")
variable.order = i + "";
}
variable.insert();
}
}
}
return 'proceed';
},
type: 'AJAXAddCatItems'
});
You can repeat lines 11-53 to add other items into the cart or better yet create a function that is called so you don't repeat the code. But hopefully this gets you started.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2015 08:29 AM
Hi.
I'm new to Service Now and I read your post. You mentioned that you were able to copy the cascaded variables from the order guide form to the other items. Can you provide a sample script on how you were able to do this?
Thank you so much.
Florence
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2015 08:58 AM
Florence, a script isn't necessary as you just need to check a box on the order guide and ensure the variables are named the same. Here are more details in the Wiki:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2015 09:58 AM
Michael is right - you shouldn't need a script to just cascade variables from the Order Guide to the individual items. I ended up abandoning the Order Guide altogether in favor of a single catalog item that collects the information for all the child items, and then an 'On Submit' script passes those variables to a GlideAjax script to create all the children without any further interaction from the user. If that's the direction you're going, I'll be happy to share those scripts with you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2016 11:50 PM
Hi Ronald,
I'm looking for a similar solution, as you described, instead of using the order guide, use a catalog item that will generate requested items for its children. can you please share your scripts?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2016 09:03 AM
I could paste my code in if you'd like, but it's exactly like what Michael Ritchie posted above. Your 'master' catalog item needs to have variables for all of the items you're ordering, and you pass those to the GlideAjax using the ajax.addParam statements.
Then, in your GlideAjax, you just repeat Michael's lines 10-53 for each item you want to add to the cart. As Michael replied to your other message, SYS_ID_OF_CAT_ITEM refers to the item you're adding to the cart. You'll also want to declare any variables that are used for multiple items before Michael's line 5 so that they're globally available in all of your subsequent 'If' blocks. It makes for a really long script. I'm ordering 11 items, and my GA is 907 lines long.
Thanks,
Ron Legters
System Administrator
Univar
T +1 425 889 3952