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

rahulpandey
Kilo Sage

Hi,

Below is the code, Just replace sp with your portalname in html (line 9 and 11)

<style>
@import url('https://fonts.googleapis.com/css?family=Reem+Kufi');
</style>
<div class="sidebar-section" style="border:1px ;height:auto">
      <h3 class="panel-heading bg-primary" style="font-family:Reem Kufi;font-size:18px; background-color:#2eb8b8;margin:0px">My Favorite Items</h3>
      <ul class="list-group no-radius alt" style="list-style:none;padding-top:10px;background-color:#ffffff">
  
          <li ng-repeat="record in data.bookmark">
         <a href="/sp?id=sc_cat_item&sys_id={{record.sys_id}}" style="font-family:NeutraText-Bold; background-color:#ffffff;">
    <div style="line-height: 30%;padding-top:5px;padding-left:2px;background-color:white">    
      <span class="sidebar-text" href="/sp?id=sc_cat_item&sys_id={{record.sys_id}}" style="color:#0077b3;font-family:NeutraText-Demi">{{record.name}}</span>
           </div>
           <hr style="color:#e6e6e6;">
         </a>
        </li>
       
      </ul>
    </div>

 

Server side

(function() {
	var record=[];
   var itm=new GlideRecord("sc_cat_item");
	itm.addEncodedQuery('u_request_shortcutsDYNAMICd6435e965f510100a9ad2572f2b47744');
  itm.query();
while(itm.next()) {
	var itemObj= {};
	itemObj.sys_id= itm.getValue("sys_id");
	itemObj.name = itm.getValue("name");
	record.push(itemObj);
}

 data.bookmark = record;
})();

 

Mark answer as correct, if it helped you.

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

I haven't tested, but have you tried this: OrderGuide - Scoped - OrderGuide | ServiceNow Developers

//Göran
Feel free to connect with me:
 

Thanks I did read that API reference guide, but it doesn't appear to facilitate what I'm looking for.  Maybe i'm missing something, but that looks like a way to read attributes of an Order Guide, not actually api calls to generate an order from an Order Guide.

Steve Chaney
Tera Contributor

I'm looking for an answer to the same question and coming up empty. Were you able to find the correct solution?

The best I can come up with, is setting the item-specific variables after the order guide has been submitted, and I would much prefer to populate the variables upfront. It seems like it should be a pretty straightforward task, but I haven't been able to locate an answer...