- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2024 12:44 PM
Thank you for your reply, I tried the script that you shared but it is not allowing me to save. Oh you are right about the last line, it should .... Also, I cant save the script you shared with me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2024 02:51 PM
The script is working but only after the assignment group is already populated and I save the incident. I want the automation to happen before saving.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2024 03:39 AM
A Business Rule will run before or after insert/update - that really means before the database action, so you need to submit/save the record either way. It sounds like you want to see the Assigned to and Assignment group fields populate on the form when the Service offering field is populated or changes. To do this you will need an onChange Client Script. Client scripts can't dot-walk to related fields, so your onChange Client Script will need to use GlideAjax to call a Script Include. This is an often-used tool to have in your belt. Here is an excellent guide on how to do this.
In your case If the newValue (service offering sys_id) is one of the two that belong to ACD or Call Center, you will pass in the caller_id as a parameter. The Script Include will run the GlideRecord from your first attempt and return the two custom fields for the client script to set on the form. Give the scripts a try, and if you're stuck post each script using the insert code icon </> and we'll get it sorted.
- 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)