Get RITM number from catalog item created in workflow

othomas1
Kilo Guru

Hello everyone, hope all is well,

I need to know how i can get the RITM number from a catalog item created in my workflow. I have a catalog item workflow, and towards the end of that workflow i am launching another catalog item. I need the RITM number from the newly launched catalog item to be in the work notes of the original catalog item, i believe this is possible i just dont know the correct syntax to use. Can anyone point me in the right direction?

Run script for logging to work notes:

current.work_notes = 'Work at Home Hardware Request has been created';

 

//var ritm = new GlideRecord('sc_req_item');
//ritm.addQuery('request');

find_real_file.png

1 ACCEPTED SOLUTION

So your scripts should be:

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
//add your requested item to the cart by sys_id of the catalog item
var item = cart.addItem('e66cb93a4f236f00259db3318110c76e', 1);

//fill in the variables on the request item form
cart.setVariable(item, 'requested_for', current.request.requested_for);
cart.setVariable(item, 'opened_by', current.request.opened_by);
cart.setVariable(item, 'work_at_home_coordinator', current.request.opened_by);
cart.setVariable(item, 'requested_for_supervisor', current.request.requested_for.manager);
var rc = cart.placeOrder();

workflow.scratchpad.request_number = rc.sys_id; //so it can be referenced later 

and

var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request', workflow.scratchpad.request_number);
ritm.query();
if (ritm.next()) {
    // access to ritm here
    current.work_notes = 'Work at Home Hardware Request has been created:' + ritm.number;
}

View solution in original post

19 REPLIES 19

there was a typo on my end, its working now.

wait its giving me the wrong number, here is my code:

 

var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request', workflow.scratchpad.request_number);
ritm.query();
if(ritm.next()) {
// access to ritm here
current.work_notes = 'Work at Home Hardware Request has been created:' + " " + ritm.number;
}

What number is it giving you? Do you only have one request item being generated? This code will grab the first RITM that has a "request" matching your request number. If you have multiple RITMS it can grab the wrong one. 

its giving me a newly created RITM number thats not associated with anything:

 

this code is picking an unrelated RITM number:

 

var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request', workflow.scratchpad.request_number);
ritm.query();
if(ritm.next()) {
// access to ritm here
current.work_notes = 'Work at Home Hardware Request has been created:' + " " + ritm.number;
}

 

find_real_file.png