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  

Populate Requested for on the Request from Business rule

Pallavi65
Tera Contributor

Hi folks,

 

I have a catalog item. So, when the catalog item is submitted, a request will be created.

There are two variables in the catalog item.

Requested for and Company.

 

So, once the item is submitted, I want to populate the Requested for on the request form with the requested for value that was selected in the cat item.

 

So, I have written a before insert BR on Request table and written this script, but the log messages are showing undefined. 

Code:
var gr = new GlideRecord('sc_cat_item');
gr.get('8cde998f2fbc69106cd7f64ef699b676');
var req_for = gr.requested_for.toString();
var req_for1 = gr.variables.requested_for.toString();

gs.log('req_for is '+req_for);  //coming undefined
gs.log('req_for1 is '+req_for1);  // here also coming undefined

current.requested_for = gr.requested_for;

 

 

Please help

 

 

Regards,

Pallavi

2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

The Requested Item (RITM) gets created right after the Request (REQ) and has access to the variables, so I would run the BR on the sc_req_item table after Insert

var gr = new GlideRecord('sc_request');
if (gr.get(current.request)) {
    var req_for = current.variables.requested_for;
    gs.log('req_for is '+req_for);
    gr.requested_for = req_for;
    gr.update();
}

 

 

ricker
Tera Guru

@Pallavi65,

Change your variable to the "Requested For" type and SN will take care of adding it to the Request and Request Item.

 

ricker_0-1675887813527.png