Use existing request number with cart.placeOrder()

David247
Tera Contributor

Greetings,

I need to be able to add a new request item to an existing request using cart.placeOrder().

My below code creates a new requested item, I just need to know how not to create a new request but use an old request number.

Thanks

var aryReqItems = ["RITM0231245", "RITM0231246"];
aryReqItems.forEach(function(item, index) {
    var grReqItem = new GlideRecord("sc_req_item");
    if (grReqItem.get("number", item)){
		var cartId = GlideGuid.generate(null);
		var cart = new Cart(cartId);
		var itemVar = cart.addItem("c26049d7db7fd740768834cc7c961918");
				
		for (var varName in grReqItem.variables) { // Get and set all variable values from the old req item for the new one.
			if (grReqItem.variables.hasOwnProperty(varName) ){
				var varValue = grReqItem.variables[varName];
				//gs.info(varName + ':' + variable);
				cart.setVariable(itemVar, varName, varValue);
			}
		}
		
		var rc = cart.placeOrder();
		
	}
});
10 REPLIES 10

Apologies, I misunderstood.

Did you try creating the RITM record and explicitly passing the function for initiating the flow for that RITM?

 

Have a look at below code snippet for how to launch flow explicitly:

 

try {
var inputs = {};
inputs['table_name'] = 'Table Name';
inputs['request_item'] = ; // GlideRecord of table: sc_req_item

var result = sn_fd.FlowAPI.getRunner().flow('flow_internal_name').inBackground().withInputs(inputs).run();

var outputs = result.getOutputs();


} catch (ex) {
var message = ex.getMessage();
gs.error(message);
}

Hi Aman, thanks for the post. Is this supposed to restart the existing flow after the flaw is fixed? Here is my script which runs, but doesn't restart the flow.

var grScReq = new GlideRecord('sc_req_item'); 
if(grScReq.get('number', 'RITM0231246')){
	try {
		var inputs = {};
		inputs['table_name'] = 'sc_req_item';
		inputs['request_item'] = grScReq; // GlideRecord of table: sc_req_item

		var result = sn_fd.FlowAPI.getRunner().flow('hardware_request').inBackground().withInputs(inputs).run();
		var outputs = result.getOutputs();

	} catch (ex) {
		var message = ex.getMessage();
		gs.error(message);
	}
}

find_real_file.png

It doesn't restart the flow, but attach new flow context for the newly created RITM.

I thinking the bad flows, that we discussed earlier should be explicitly cancelled/deleted as well, when you cancelling/deleting the RITMs.
Cancelling I know will have no reprucusions, but deleting might have some, please explore a lil bit around that, and share

For cancelling, I found something in HI:

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0750702