Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

"Requested for" of the RITM to be the same as "Requested for" of the variable. How can I achieve?

Vaishnavi35
Tera Guru

Hi,

 

I have written a BR that creates an RITM when Idea is Accepted.

Here is the code,

(function executeRule(current, previous /*null when async*/) {
createRequest();
function createRequest() {
var cart = new Cart();   //calling the cart API
var item = cart.addItem('389e052687e20e909e70c91acebb351f');   //sys_id of the catalog item I want to fire
cart.setVariable(item, 'u_project_name', current.short_description); //sets catalog variable to the email's subject
cart.setVariable(item, 'u_project_description', current.description);
cart.setVariable(item, 'u_cost_center_c', current.u_cost_center);
cart.setVariable(item, 'u_portfolio_c', current.portfolio);
cart.setVariable(item, 'u_program_c', current.u_program);
cart.setVariable(item, 'u_requested_for_prj', current.u_requested_for);
cart.setVariable(item, 'u_request_made_by', current.submitter); 
cart.setVariable(item, 'u_manager', current.u_requested_for.manager); 
cart.setVariable(item, 'u_demand_number', current.demand.number); 
var rc = cart.placeOrder();   //this launches the catalog item, and creates a request object.   rc = the request object
updateRITM(rc.sys_id);   //call a function immediately to update the ritm.   This must be a nested function, otherwise inbound actions get weird.

           //also, we're passing the sys_id of the request so we know what RITM to grab.
}
function updateRITM(req){
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request', req);   //req is what we passed from the previous function. the sys_id of the request.
ritm.query();
while (ritm.next()){
ritm.requested_for = current.u_requested_for; 
gs.info('current.u_requested_for: ' + current.u_requested_for);  

 ritm.update();
}
   }

 

ritm.requested_for = current.u_requested_for; - this statement does not work.
u_requested_for is a field on the Idea form. requested_for is the field on the RITM form.
Idea form u_requested_for should be mapped onto the RITM requested_for. But it does not work.
On the RITM form, requested_for displays the submitted by value not the requested for value.
 
HELP?
 
Thanks,
Vaishnavi
1 ACCEPTED SOLUTION

AshishKM
Kilo Patron
Kilo Patron

Hi @Vaishnavi35 , 

Please use the below updated code.

 

function updateRITM(req){
var req = new GlideRecord('sc_request');
req.addQuery('sys_id', req);   //req is what we passed from the previous function. the sys_id of the request.
req.query();
if (req.next()){
req.requested_for = current.u_requested_for; 
gs.info('current.u_requested_for: ' + current.u_requested_for);  
req.update();
}

 

-Thanks,

AshishKM


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

View solution in original post

1 REPLY 1

AshishKM
Kilo Patron
Kilo Patron

Hi @Vaishnavi35 , 

Please use the below updated code.

 

function updateRITM(req){
var req = new GlideRecord('sc_request');
req.addQuery('sys_id', req);   //req is what we passed from the previous function. the sys_id of the request.
req.query();
if (req.next()){
req.requested_for = current.u_requested_for; 
gs.info('current.u_requested_for: ' + current.u_requested_for);  
req.update();
}

 

-Thanks,

AshishKM


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution