- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2024 11:59 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2024 06:39 AM
Still making progress - almost there. If these are the correct custom field names on the location table, you need to force the sys_ids/values to a string type. Here are two methods for doing that
assignment_group: locationGr.u_assignment_group.toString(), // Adjust field name as necessary
assigned_to: locationGr.getValue('u_location_support')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2024 05:51 AM
If the Client callable box is checked after text is entered in the Script box, it does not update the script appropriately - making it client callable. Here's what yours should look like. I would get in the habit of always returning something, so it avoids browser errors and is easier to troubleshoot - I'm not getting a response, did my Script Include run, or just not return anything?
var LocationUtils = Class.create();
LocationUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
// This function is callable from the client script
getLocationDetails: function() {
var locationId = this.getParameter('sysparm_location_id'); // Get the location sys_id
var locationGr = new GlideRecord('cmn_location');
if (locationGr.get(locationId)) {
// Create an object to hold the results
var result = {
assignment_group: locationGr.u_assignment_group, // Adjust field name as necessary
assigned_to: locationGr.u_location_support // Adjust field name as necessary
};
return JSON.stringify(result); // Return the result as a JSON string
}
return 'location not found'; // Return if not found
},
type: 'LocationUtils'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2024 06:00 AM
I did not get anything this time..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2024 06:13 AM
Adding some temporary logs to see if the script is running, and how far it is getting.
var LocationUtils = Class.create();
LocationUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
// This function is callable from the client script
getLocationDetails: function() {
gs.addInfoMessage('Script Include running')
var locationId = this.getParameter('sysparm_location_id'); // Get the location sys_id
gs.addInfoMessage('Location = ' + locationId)
var locationGr = new GlideRecord('cmn_location');
if (locationGr.get(locationId)) {
gs.addInfoMessage('Location record found')
// Create an object to hold the results
var result = {
assignment_group: locationGr.u_assignment_group, // Adjust field name as necessary
assigned_to: locationGr.u_location_support // Adjust field name as necessary
};
gs.addInfoMessage('Result = ' + JSON.stringify(result))
return JSON.stringify(result); // Return the result as a JSON string
}
gs.addInfoMessage('Location record not found')
return 'location not found'; // Return if not found
},
type: 'LocationUtils'
});
Which of these messages are you seeing when you change Service Offering to ACD or Call Center after ensuring the Location field is populated?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2024 06:29 AM
This is what I am getting....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2024 06:39 AM
Still making progress - almost there. If these are the correct custom field names on the location table, you need to force the sys_ids/values to a string type. Here are two methods for doing that
assignment_group: locationGr.u_assignment_group.toString(), // Adjust field name as necessary
assigned_to: locationGr.getValue('u_location_support')