Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Hello,

 

Please check what value is coming in current.variables.location. Please use the below code and let me know what value is coming in location.

 

(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('name', current.variables.location);
ritm_gr.query();
if(ritm_gr.next())
{
current.u_service_location_test=ritm_gr.sys_id;
current.update();
}


})(current, previous);

 

Bindhu1
Tera Contributor

on logs i am able to see the location i selected when i submitting the request but on RITM its still the same 'Gilbert'.

Bindhu1_0-1669830762402.png

Bindhu1_1-1669830816114.png

 

 

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.

Bindhu1
Tera Contributor

Thanks a lot !!! it worked.

it worked when I tried above code using Before BR insert/update but when i did same using After BR Insert/update the RITM record itself not created. 

MercBuilding
Tera Guru

Hi @Bindhu1 ,

     I would suggest to use Run script activity in workflow to update the location on sc_req_item table instead of using after BR. After BR with current.update() will affect the performance and not best practise to use it. So use current.u_service_location=current.variables.location in Run script activity of workflow.

 

Hope this helps!