The Zurich release has arrived! Interested in new features and functionalities? Click here for more

set value of a reference field through a fix script

Prakash Pareek
Tera Expert

1. I wanted to set value for reference field 'abc' through a fix script.

2. I have a reference field 'xyz' in my table that is inherited from another table .. So wanted to set value for that reference field also through the fix script.

 

var requestedGR = new GlideRecord('sc_t');
var queryString = "sys_id=2f6df0ffde6fd00000ca8ebd576543e";
requestedGR.addEncodedQuery(queryString);
requestedGR.query();
while (requestedGR.next()) {
requestedGR.setValue('u_abc','rty');
requestedGR.setValue('u_xyz','lmno');
requestedGR.updateWithReferences();
}

 

6 REPLIES 6

Aman Kumar S
Kilo Patron

Hi @Prakash Pareek ,

If you are trying to populate reference field, you will need to pass sys_id as value. If you are willing to use only the display the script should be as below:

 

var requestedGR = new GlideRecord('sc_t');
var queryString = "sys_id=2f6df0ffde6fd00000ca8ebd576543e";
requestedGR.addEncodedQuery(queryString);
requestedGR.query();
while (requestedGR.next()) {
requestedGR.setDisplayValue('u_abc','rty');
requestedGR.setDisplayValue('u_xyz','lmno');
requestedGR.update();
}

Best Regards
Aman Kumar

In while loop , u actually need to add one more glide record of the reference to the user table ..and get the sys id of the user  and then create a second while loop .. we need to setValue of the desired field in this while loop.

if ur tables record have different sys id in different instances then this is the way.. else directly setValue with the sys_id