Business Rule not setting Reference Field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2024 11:25 AM
I'm currently trying to run a before business rule that will set the built-in "location" field in the "Users" (sys_user) Table based on a custom "location" (u_location) string field on the same table. The issue is that no matter what I try, the built-in "location" field isn't being set.
I can see in the session log that it looks like it's setting the sys_id of the cmn_location record to the reference field, but the field still appears blank.
Here is a copy of my before business rule:
(function executeRule(current, previous /*null when async*/) {
// Query the Locations (cmn_location) Table
// Find a record that contains the value of the custom location field (u_location)
var gr = new GlideRecord('cmn_location');
gr.addQuery('u_name_and_address', "CONTAINS", current.u_location);
gr.query();
// Set the value of the built-in location field (location) to the sys_id of the Location Table record
if (gr.next()) {
current.location = gr.sys_id;
}
})(current, previous);
I have already tried all of suggested solutions in the following posts, to no avail:
- Business Rule is not setting the reference field value
- Setting value of reference fields using Business Rule
- Setting a reference field in business rule isn't working correctly
- how to use business rule to set reference field based on string value
Any help would be much appreciated!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2024 05:32 PM
Hi, can you see the field content from a list view?
Have you checked xml of an updated record to confirm that the field is empty, and not just an issue with display?
Is there a QBR hiding the cmn_location data from user view?
If the field is empty, your BR is running and populating the correct sys_id, then perhaps there is another script running after your BR (that is emptying the field). If not a BR then potentially it is flow or workflow and you could check flow\workflow context to see if any of these are running during a record update.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2024 09:35 AM
Hey Tony,
The content doesn't show up in a list view. Not sure how to check the xml, but I can confirm that there is no other script affecting the OOTB location field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2024 01:42 PM
From UI context menu (or header) of list or individual records right click and from the menu select Show xml, Note: from a list this will return xml for all records returned by your query, so might be easier\faster to view example records individually.
Perhaps next step is to add some debugging\logging to the script that you are using to set the value, so that you can confirm that a value is being populated by the script and that the value is correct\expected for the table that the reference field maps too. Maybe something like
(function executeRule(current, previous /*null when async*/) {
// Query the Locations (cmn_location) Table
// Find a record that contains the value of the custom location field (u_location)
gs.info('My debugging | u_location | ' + current.u_location);
var gr = new GlideRecord('cmn_location');
gr.addQuery('u_name_and_address', "CONTAINS", current.u_location);
gr.query();
// Set the value of the built-in location field (location) to the sys_id of the Location Table record
if (gr.next()) {
current.location = gr.sys_id;
gs.info('My debugging | set location | ' + current.location);
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2024 07:22 PM
@EvanAAmyotte Could you please try the following script and see if it works.
(function executeRule(current, previous /*null when async*/) {
// Query the Locations (cmn_location) Table
// Find a record that contains the value of the custom location field (u_location)
var gr = new GlideRecord('cmn_location');
gr.addQuery('u_name_and_address', "CONTAINS", current.u_location);
gr.query();
// Set the value of the built-in location field (location) to the sys_id of the Location Table record
if (gr.next()) {
current.location = gr.getValue('sys_id');
}
})(current, previous);
Also, please check if there is any reference qualifier set on the OOTB location field which is not letting the value set on the field.