- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2019 08:36 AM
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
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2019 02:18 PM
Ok, glad you asked. That's correct you have to set it.
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!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2019 10:07 AM
Hello,
The Cart API uses the cat_item to order the item and proceed forward through it's own workflow, if applicable.
I'm unsure what you mean by:
cart.setVariable(item,'parent_ritm',workflow.scratchpad.number); -- This gives value as undefined
As you're not telling us that you're setting the workflow.scratchpad.number to anything. When did you do that? Where did you do that? Because in this script, its not here...
Then this...
//cart.parent_ritm = current.variables.number; -- This is not working
isn't going to work, because that field doesn't exist on the cat_item...you'd have to either pass it in as a variable (like you attempted to do above) or insert the item, then gliderecord query through sc_req_item filtering for your new record's sys_id and then add it after the fact.
So please elaborate a bit more on what all is going on here?
Thanks!
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2019 08:25 AM
Hi Allen,
Thanks for your response.
My intent is to get the values from the existing RITM to the new RITM , so parent_ritm is a variable on my new RITM , and number is the requested item number field on the existing RITM from which the new RITM is getting created in thee workflow.
So basically my requirement is to move the variable values from the existing RITM to the newly created RITM.
Thanks in advance

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2019 10:26 AM
Hi,
Yes, I understand that. What I said in my post is:
cart.setVariable(item,'parent_ritm',workflow.scratchpad.number); -- This gives value as undefined
Doesn't make sense because you haven't set the workflow scratchpad number...to a value. Where did you do this?
And
//cart.parent_ritm = current.variables.number; -- This is not working
Doesn't work because that's not a field on the cat_item.
So you didn't really add anything to this thread by your post just a short bit ago.
Please read my response and answer the question(s) I have...or do them...
Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2019 11:23 AM
Hi Allen,
workflow.scratchpad.number -- will this line not be having value of the RITM in the number field ? Do we need to set this or will it not get the value from the field('number' field which has the existing RITM). I am using the workflow.scratchpad first time so I am not sure that I am using it correctly.
And yes I understood this line will not work
cart.parent_ritm = current.variables.number; -- This is not working
Thanks in advance