Copy catalog item variable field value to the field on RITM table

Bindhu1
Tera Contributor

Hi Team,

I need to copy catalog item variable field value [location] which is a reference field referring to custom table [u_one_team_workflow_location], to custom field [u_service_location_test] on RITM which is also reference field referring to same custom table.

I have tried all possible ways but unable to get the value on RITM field [u_service_location_test].

please refer the image 

custom table:

Bindhu1_0-1669820764119.png

custom field on RITM

Bindhu1_1-1669820838818.png

 

Variable on cat item

Bindhu1_2-1669820968937.png

 

Tried Solution

before BR on sc_req_item table on insert and update

Bindhu1_3-1669821167891.png

 

Thanks

 

 

 

 

 

1 ACCEPTED SOLUTION

Hello,

 

I see maybe the name field is u_name in the backend. Then please use the below:-

 

(function executeRule(current, previous /*null when async*/) {
gs.log('location'+current.variables.location);
var ritm_gr = new GlideRecord('u_one_team_workflow_location');
ritm_gr.addQuery('u_name', current.variables.location);
ritm_gr.query();
if(ritm_gr.next())
{
current.u_service_location_test=ritm_gr.sys_id;
current.update();
}


})(current, previous);

 

Please mark my answer as correct based on Impact.

View solution in original post

9 REPLIES 9

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

Please change the BR to after insert/update on sc_req_item table and add current.update();

 

As I do not think the variables get attached to the RITM before insertion so the value will not come in the before BR

 

Please mark my answer as correct based on Impact.

Bindhu1
Tera Contributor

Yes, I tried it but did not work.

I just noticed you are using a lookup select box with name. You need to use glide record to that one team workflow location table:-

 

Create an after insert/update on sc_req_item table with below code:-

 

(function executeRule(current, previous /*null when async*/) {

var ritm_gr = new GlideRecord('u_one_team_workflow_location');
ritm_gr.addQuery('name', current.variables.location);
ritm_gr.query();
if(ritm_gr.next())
{
current.u_service_location_test=ritm_gr.sys_id;
current.update();
}


})(current, previous);

 

Saurav11_0-1669828241219.png

 

 

Please mark my answer as correct based on Impact.

 

 

 

Bindhu1
Tera Contributor

The thing is whenever i give after BR inster/update and current .update  the RITM itself not getting created.

 

and i tried the above code using Before BR , for every cat item created with diff location, on RITM field u_service_location_test its populating only single value 'Gilbert.

Bindhu1_0-1669829482618.png