How to copy table sys_user field value to RITM sys_user field

chrish5
Giga Guru

I have the below RITM workflow script that does a query on the u_semi_annual_audit_applications table and when the RITM application field matches  up with table application, I want to get the table approver, which is a sys_user field and copy it to the RITM semi_annual_audit_approver field which is also a sys_user fields.  Below is my script, but it's not working.  Any help would be appreciated. 

 

 

var gr = new GlideRecord('u_semi_annual_audit_applications');
gr.addQuery('u_application',current.variables.application);
gr.query();
if (gr.next()){
current.variables.semi_annual_audit_approver == gr.u_approver;
}
1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@chrish5 Could you please update the script as follows and see if it works.

 

var gr = new GlideRecord('u_semi_annual_audit_applications');
gr.addQuery('u_application',current.variables.application+'');
gr.query();
if (gr.next()){
current.variables.semi_annual_audit_approver = gr.u_approver+'';
}

Hope this helps.

View solution in original post

4 REPLIES 4

Sandeep Rajput
Tera Patron
Tera Patron

@chrish5 Could you please update the script as follows and see if it works.

 

var gr = new GlideRecord('u_semi_annual_audit_applications');
gr.addQuery('u_application',current.variables.application+'');
gr.query();
if (gr.next()){
current.variables.semi_annual_audit_approver = gr.u_approver+'';
}

Hope this helps.

Jim Coyne
Kilo Patron

@Sandeep Rajput's code should work.  Your problem is the use of the "==" comparison operator instead of the "=" assignment operator.  Your code should be throwing an error in the logs.

 

jMarshal
Mega Sage
Mega Sage

I could be wrong, but I don't think you wanna use the "==" operator when assigning a value...you may be successful just changing the line to "current.variables.semi_annual_audit_approver = gr.u_approver;".

If not, maybe try using some intermediate variables and alerts to debug...

 

var appName = current.variables.application;
var auditApprover = "";
gs.alert(appName);
 
var gr = new GlideRecord('u_semi_annual_audit_applications');
gr.addQuery('u_application',appName);
gr.query();
 
if (gr.next()){
 
auditApprover = gr.u_approver
gs.alert(auditApprover);
current.variables.semi_annual_audit_approver = auditApprover;
 
}

Jim Coyne
Kilo Patron

Remember to mark any posts as helpful as well.  Whereas Sandeep's answer worked for you, it does nothing to teach people anything.  It's always helpful to understand the solution.  I hate "do this" answers.