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.

Business Rule not setting Reference Field

EvanAAmyotte
Tera Contributor

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.

2024-06-20 12_14_08-Script Debugger - Work - Microsoft​ Edge.png

 

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:

Any help would be much appreciated!

5 REPLIES 5

Hey Sandeep,

 

I updated the script as you suggested. Still seeing the same result. I also confirmed there is no reference qualifier on the OOTB location field.

EvanAAmyotte_0-1719246186943.png