Having issue with Before business rule not populating fields on incident form

Rhonda9
Tera Expert

Hello, I created a business rule that is not working as expected.   I was asked to auto assign incidents if the service offering is "acd" or "call center" on the UI side to the affected user's location location support  to the Assigned to field and the location assignment group to the assignment group field fore saving the form.  What am I doing wrong?

 Insert and update is checked

 condition :    current.service_offering == 'ACD' || current.service_offering == 'Call Center'

(function executeRule(current, previous /*null when async*/) {

// Check if the affected user (caller_id) is set
if (current.caller_id) {
// Fetch the affected user's record
var userGr = new GlideRecord('sys_user');
if (userGr.get(current.caller_id)) {
// Get the user's location
var userLocation = userGr.location; // Assuming this is the field for location

// Fetch the location record
var locationGr = new GlideRecord('cmn_location');
if (locationGr.get(userLocation)) {
// Set the Assignment Group field to the location's Location Support
current.assignment_group = locationGr.u_location_support; // Adjust field name if necessary

// Set the Assigned To field to the location's Assignment Group
current.assigned_to = locationGr.u_assignment_group; // Adjust field name if necessary
}
}
}

})(current, previous);

Thank you in advance