set value of a reference field through a fix script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2022 10:10 PM - edited 11-15-2022 10:21 PM
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();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2022 12:25 AM
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();
}
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2022 02:07 AM
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