add items to order guide dynamically
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2014 10:28 AM
I am looking for a good way to add catalog items to an order guide using custom logic - without having to specify all of the possible items in the rule-base.
For example, lets say there are 15 mobile phone models/plans that are in the catalog and could be added to the order guide. Additionally, more models come and go regularly.
The logic exists elsewhere in the system using script include to indicate who is allowed to request which model. These rules are too complicated to easily be put directly into the order guide rules (e.g. not as simple as 'Department == IT' or 'Title == Director').
I would like to see if/where I can intercept the logic after 'Describe Needs' and add the correct Catalog items into the Order Guide.
psuedo code idea:
//on 'Describe Needs' Submit action
var orderGuide = current;
var itemFinder = new CatalogItemChooser();
var availableItems = itemFinder.FetchAvailableCatalogItems(orderGuide.variables.requested_for);
//this will consult custom provision logic based on the requested_for user and bring back a list of items to add to the order guide.
orderGuide.items = availableItems;
Am I missing something simple here?
I don't think the rule base is complex enough to handle this easily.
I know I could use the rules, add every item individually with a rule - and then make a call to the custom logic to return a true/false answer to determine if it should be included, but that seems like more maintenance than should be required.
Thanks for any help or ideas.
Scott.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2015 12:06 PM
Hey Scott,
I plan to implement something similar, and I was hoping you had some feedback about this question. Did you use a solution similar to what Travis provided?
Thanks,
Justin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2017 09:07 AM
Hi All,
I had exactly the same requirement, and was getting really annoyed that there is no way around it, the fact that Order Guide variables are NOT stored anywhere on the server, and Community does not have a clear answer. This thread was by far the most useful to get me in the right direction. I finally cracked it, and will explain how.
The basic requirement was a New Starter order guide, with slush buckets (List Collectors) that display Catalog Items in certain categories (i.e Software category, Hardware category, Consumables category). Any Catalog Item selected in the List Collector should be rendered on the Order Guide second page.
The solution that has worked for me:
So, List collectors point to Catalog Items with reference qualifier on categories. I created some hidden Single Line Text variables, calling them "datafields" (i.e software_datafield, hardware_datafield), and relevant UI Policy to actually hide these from the user, as I only need it to store an array (comma separated string) of selected catalog item sys_id's.
Client Script(s) written to run onChange of the List Collector variable(s). Purpose is to build the catalog item sys_id string in a field that is easy to read:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.setValue('software_datafield', newValue);
}
Created a CUSTOM TABLE, called Order Guide Variables, which acts pretty much the same way as the shopping cart (sc_cart). In this table, I have the following fields:
User [u_user]
Software Datafield [u_software_datafield]
Hardware Datafield [u_hardware_datafield]
etc. You can create any fields you would want to capture from your Order Guide.
The purpose of this is that EACH user using an Order Guide (we are lucky, we only have this single one, so you might need some enhancement here, or multiple similar tables) would eventually trigger the population of a single record (per user) in this table to store my Order Guide variables I need to re-use.
Then, an onSubmit catalog client script on the Order Guide to populate the Order Gudie Variables table. If this is the first time the user submits the Order Guide, it will create a record, if a record already exists, it will be updated with the new variable values:
function onSubmit() {
var User = g_user.userID;
var SWData = g_form.getValue('software_datafield');
var HWData = g_form.getValue('hardware_datafield');
var AppData = g_form.getValue('application_datafield');
var ga = new GlideAjax('OrderGuideVariableCapture');
ga.addParam('sysparm_name', 'createOGvars');
ga.addParam('sysparm_user', User);
ga.addParam('sysparm_software', SWData);
ga.addParam('sysparm_hardware', HWData);
ga.getXMLWait();
}
The onSubmit client script communicates with the following Script Include (it is Synchronous, since it is onSubmit, so we must wait for it to complete before we can proceed):
var OrderGuideVariableCapture = Class.create();
OrderGuideVariableCapture.prototype = Object.extendsObject(AbstractAjaxProcessor, {
createOGvars: function() {
var retVal = ''; // Return value
var userID = this.getParameter('sysparm_user');
var SWData = this.getParameter('sysparm_software');
var HWData = this.getParameter('sysparm_hardware');
var gr = new GlideRecord('u_order_guide_variable');
gr.addQuery('u_user', userID);
gr.query();
if(gr.next()){
gr.u_software_datafield = SWData;
gr.u_hardware_datafield = HWData;
//gr.u_application_datafield = AppData;
gr.update();
}
else{
gr.initialize();
gr.u_user = userID;
gr.u_software_datafield = SWData;
gr.u_hardware_datafield = HWData;
//gr.u_application_datafield = AppData;
gr.insert();
}
return "Order Guide Variables stored for " + userID;
}
});
Then finally, in the Order Guide I added the Script field to the OG form, and used the following script to aut-render the selected items without the need of a Rule Base:
var gr = new GlideRecord('u_order_guide_variable');
gr.addQuery('u_user', gs.getUserID());
gr.query();
if(gr.next()){
var SWarray = gr.u_software_datafield;
var HWarray = gr.u_hardware_datafield;
var SWarraySplit = SWarray.split(",");
for (i = 0; i < SWarraySplit.length; i++) {
guide.add(SWarraySplit[i]);
}
var HWarraySplit = HWarray.split(",");
for (j = 0; j < HWarraySplit.length; j++) {
guide.add(HWarraySplit[j]);
}
}
So, the List Collectors pick up catalog items, those are copied to string variables, onSubmit script populates a custom table, and the order guide script looks up custom table and uses it to render each an every item that exists in relevant custom table field.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2020 06:34 AM
Thanks for this
Also thanks to
The only issue I had when I used the above was that getXMLWait() is not supported in the portal.
So I had to amend my onSubmit catalog client script to the following: -
function onSubmit() {
if (g_scratchpad.isFormValid)
return true;
var User = g_user.userID;
var HWData = g_form.getValue('hardware_datafield');
var ga = new GlideAjax('OrderGuideVariableCapture');
ga.addParam('sysparm_name', 'createOGvars');
ga.addParam('sysparm_user', User);
ga.addParam('sysparm_hardware', HWData);
ga.getXMLAnswer(setAnswer);
return false;
function setAnswer(answer) {
var actionName = g_form.getActionName();
g_scratchpad.isFormValid = true;
g_form.submit(actionName);
}
}
Note, I've only used the Hardware Data param/field so you may need to add software, app or any other data fields accordingly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2020 06:44 AM