- 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 04:23 AM
Thank you for the resources...
This is what I have and it's still not working for me:
Client Script with service offering being the onChange field Name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2024 05:04 AM
You need to use the sys_id of the service offering, not the name since this is a reference field the value is a sys_id. I've changed your alert to show you the value of the service offering selected. In your first script you were getting the location of the caller, this script is getting the incident location. If this change was intended the rest of the client script should be fine. Added an alert on response to confirm that is the expected value.
function onChange(control, oldValue, newValue, isLoading) {
// Check if the form is loading or if no new value is selected
if (isLoading || !newValue) {
return;
}
alert('Service offering = ' + newValue);
// Check if the selected value is "ACD" or "Call Center"
if (newValue === 'sys_id' || newValue === 'sys_id') {
var locationSysId = g_form.getValue('location'); // Get the location field value
// Ensure the location field is not empty
if (locationSysId) {
// Call the Script Include
var ga = new GlideAjax('LocationUtils');
ga.addParam('sysparm_name', 'getLocationDetails');
ga.addParam('sysparm_location_id', locationSysId);
ga.getXMLAnswer(function(response) {
alert(response);
// Parse the response
var result = JSON.parse(response);
if (result) {
// Set the Assignment Group and Assigned To fields
g_form.setValue('assignment_group', result.u_assignment_group);
g_form.setValue('assigned_to', result.u_assigned_to);
} else {
g_form.addErrorMessage('Could not retrieve location details.');
}
});
} else {
g_form.addErrorMessage('Please select a location.');
}
}
}
If it's still not working post the Script Include (client script was posted twice above)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2024 05:35 AM
Thank you, I copied your script and added the sys id's and I am now getting the message "Could not retrieve location details".
Here is the Script Include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2024 05:38 AM
The (old) Client Script still re-posted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2024 05:43 AM
Okay, I think I accidently copied the client script into the Script Include.
Here it is....