Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to use cart api in flow designer

Anna_Servicenow
Tera Guru

I have used the below script that i found in community to create two ritm under same REQ. I did run it from background script and it is working fine. How can i trigger it from flow designer so that this is triggered as soon as request is submitted. 

 

var catalogItem = 'b70c34e807334c10540bf2508c1ed073'; // catalog item sys_id

var jsonArray = [{"requested_for":"Abel Tuter","requested_by":"Sam Jone","model":"Hyundai","quantity":1,"device_model_name":"Car-Petrol"},{"requested_for":"Fred Luddy","requested_by":"Amy Jone","model":"Honda","quantity":1,"device_model_name":"Car-Diesel"}];

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);

for(var i=0;i<jsonArray.length;i++){

var jsonObj = jsonArray[i];
var parser = JSON.parse(JSON.stringify(jsonObj));

var item = cart.addItem(catalogItem,1);
cart.setVariable(item, 'requested_for', parser.requested_for);
cart.setVariable(item,'requested_by',parser.requested_by);
cart.setVariable(item,'model', parser.model);
cart.setVariable(item,'quantity', parser.quantity);
cart.setVariable(item,'device_model_name', parser.device_model_name);

}

var rc = cart.placeOrder();
gs.info('Request Number is: ' + rc.number);
0 REPLIES 0