Cart API

Anubhav24
Mega Sage
Mega Sage

Hi All,

I am using CART API to create new RITM from one of my existing workflows after one task is closed , what I want to do is on the new RITM I have a variable Parent RITM and I want the original RITM number on this new RITM created through cart API.

My script is below what I am trying:

-------------------------------------------------

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('52a10d98db5dc010fc967b386896192f');
//cart.parent_ritm = current.variables.number; -- This is not working
cart.setVariable(item,'parent_ritm',workflow.scratchpad.number); -- This gives value as undefined
// another piece of code --- This one I am not sure how it is working
var request =
{

'variables':{
'parent_ritm': current.variables.number
}
};
//var cart_item_id = "4d69b672c322320076173b0ac3d3ae79";
//var cartDetails = cart.updateItem(request, cart_item_id);

//


var rc = cart.placeOrder();
gs.addInfoMessage(rc.number);

 

Thanks

1 ACCEPTED SOLUTION

Ok, glad you asked. That's correct you have to set it. 

https://docs.servicenow.com/bundle/helsinki-servicenow-platform/page/administer/using-workflows/conc...

So you'd want to do something like:

workflow.scratchpad.number = current.sys_id;

So now it holds the sys_id of the current RITM.

then...when you're assigning variable values for the new item your ordering, you can use workflow.scratchpad.number if the variable is a reference field to the sc_req_item table.

So then this line would work:

cart.setVariable(item,'parent_ritm',workflow.scratchpad.number); -- This gives value as undefined

alternatively...you could have just used:

cart.setVariable(item,'parent_ritm',current.sys_id);

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

5 REPLIES 5

Ok, glad you asked. That's correct you have to set it. 

https://docs.servicenow.com/bundle/helsinki-servicenow-platform/page/administer/using-workflows/conc...

So you'd want to do something like:

workflow.scratchpad.number = current.sys_id;

So now it holds the sys_id of the current RITM.

then...when you're assigning variable values for the new item your ordering, you can use workflow.scratchpad.number if the variable is a reference field to the sc_req_item table.

So then this line would work:

cart.setVariable(item,'parent_ritm',workflow.scratchpad.number); -- This gives value as undefined

alternatively...you could have just used:

cart.setVariable(item,'parent_ritm',current.sys_id);

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!