Submit order guide via script

twenger26
Giga Contributor

Hi,

I've scoured SN documentation and haven't been able to figure this out.   I want to submit an Order Guide with a script by filling in the Parent variables of the order guide, but then also fill in the sub catalog form variables.  I can't find any solution/example out there of someone doing this.  Does anyone know if this is possible?  

Below is some code I've tried to throw together after sifting through numerios discussions, but it doesn't work.  It does generate the catalog request from the order guide, but it doesn't fill in the variables for the sub catalog item.

// Creating the object to later be JSON encoded 
var json = {"opened_by":"e4e41fabd0e4f140dc01f1622e5e2478","requested_for":"e4e41fabd0e4f140dc01f1622e5e2478","department":"ee83c00dc5d17000de6eea6bb39e8f25",
 "items":
 [
  {
    "sys_id": "dc512293c54d3000de6eea6bb39e8f92",
    "variables":
        {"name":"blah", 
         "Pager_owner":"dude", 
         "Similar_pager_number":"2625421", 
         "Comments":"comments", 
         "pager_confirmation":"Yes"
		},
	  "sysparm_quantity": "1"
  }
 ]
};
 
var gr = new GlideRecord("sc_cat_item_guide");
if (gr.get("name","Auto Order Guide Test")) {
  var sog = new SNC.ScriptableOrderGuide(gr.getValue("sys_id"));
  var result = sog.process(new JSON().encode(json));
  if(!result)
    gs.log("Processing the scriptable order guide failed with message: " + sog.getMessage());
  else { 
    var request = sog.getRequest();
    gs.log("Request created - " + request.sys_id); } 
}

 

7 REPLIES 7

I am also looking for a way to accomplish this. Has anyone had any luck?

Trevor Muhl
Kilo Sage

I found a solution that works best when you only need to set a handful of item variables included in an order guide. If you have a lot of variables, this would result in a lot of complexity.

 

As we've seen, the ScriptableOrderGuide API seems to only have access to the order guide's variables. One workaround is to map order guide variables to individual catalog item variables. You can create "hidden" variables within the order guide if you don't want them visible anywhere and usable only through a script.

 

For each item variable you need to set via script:

  1. Create a matching variable within the order guide.
  2. Within the rule base for the child catalog item, create a new "Item Variable Assignment".
  3. In that new assignment record, map the new order guide variable to the desired item variable.

As a result, Item Variable Assignments act as an interface we can use to set item variables via script.

 

Item Variable Assignment.png

 

I eventually had to find a solution that supported hundreds of variables in child (sub) catalog items. Creating additional variables and variable assignments for each of them was just too much.

 

Instead, I did the following for each child catalog item:

  1. Bundled the existing variables for the child catalog item into a new variable set.
  2. Added the new variable set to the original catalog item, so that it continues to work as intended.
  3. Added the new variable set to the order guide.

Then, I completed these steps on the order guide:

  1. Created a new UI policy to hide all new variables sets.
  2. Enabled "Cascade Variables" on the order guide.

Now, the same variables are present on the order guide and the child catalog item. Since the variable sets are hidden on the order guide, the guide itself is not affected. Each variable can be set with SNC.ScriptableOrderGuide. And all variables will be cascaded down to the individual catalog items.

 

Note: You will have to resolve any name conflicts among variables in variable sets added to the order guide. No two variables can share the same name, even in different sets.