Create Alert when a particular group is selected in Incident
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2025 02:52 AM
Hi,
I need to create a alert if a group is populated based on the configuration item selected. The group is configuration item support group. But this doesn' work.
/*function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.getReference('cmdb', function(record) {
if (record.support_group && g_form.getValue('ass_group') !== record.sup_group) {
if (confirm(getMessage('Do you want to change the assigment group for the selected CI support group')))
g_form.setValue('ass_group', record.sup_group);
}
});
}*/
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
// Need this script to run even when the value = '' to reset assignment group to empty
if (isLoading || newValue == '') {
//g_form.setValue("ass_group",'');
return;
}
// getReference is used with a call back function to maintain best practices.
//g_form.setValue("ass_group",'');
var assgn_grp = g_form.getReference('cmdb_ci', setassigngrp);
}
function setassigngrp(ci) {
var group = g_form.getValue('ass_group');
var category = g_form.getValue('category');
if (group == '') {
g_form.setValue("ass_group", ci.support_group);
}
else if (ass_group == '5ca69d10c370b550474c223599013190'){
alert('Dear ServiceDesk team. Please consider "Process_ServiceNow assignment" group is not a real ');
}
if (group != '' && ci.sup_group != '' && category != 'it' ) {
var answer = confirm("Do you want to overwrite the current assignment group set ?");
if (answer == true)
g_form.setValue("ass_group", ci.sup_group);
}
else {
//Call Server side script include to fetch the sys id of IT Service Desk group only if CI doesnot have support group
//var grp = new GlideAjax('SysIDofITServiceDesk');
//grp.addParam('sysparm_name','id');
//grp.getXMLAnswer(assign);
}
//function assign(response)
{
var ans = response;
//g_form.setValue("ass_group",ans);
}
}
16 th line didn't work. Let me know if anyone have idea.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2025 02:59 AM
Hello @Arun Priya ,
Please try the below full script depending upon your requirement
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
// Get CI details and pass them to callback function
g_form.getReference('cmdb_ci', setAssignmentGroup);
}
function setAssignmentGroup(ci) {
if (!ci) return;
var currentGroup = g_form.getValue('assignment_group');
var category = g_form.getValue('category');
if (!currentGroup && ci.support_group) {
// If assignment group is empty and CI has a support group, set it
g_form.setValue("assignment_group", ci.support_group);
} else if (currentGroup === '5ca69d10c370b550474c223599013190') {
// Alert for ServiceDesk team
alert('Dear ServiceDesk team. Please note that "Process_ServiceNow assignment" group is not a real group.');
}
// Ask the user if they want to overwrite an existing assignment group
if (currentGroup && ci.support_group && category !== 'it') {
var answer = confirm("Do you want to overwrite the current assignment group with the selected CI's support group?");
if (answer) {
g_form.setValue("assignment_group", ci.support_group);
}
}
// If CI has NO support group, call Script Include to fetch IT Service Desk group sys_id
else if (!ci.support_group) {
var ga = new GlideAjax('SysIDofITServiceDesk'); // Replace with your actual Script Include name
ga.addParam('sysparm_name', 'id');
ga.getXMLAnswer(assignGroup);
}
}
function assignGroup(response) {
if (response) {
g_form.setValue("assignment_group", response);
}
}
Regards,
Debasis
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2025 03:02 AM
Hello @Arun Priya
You can try this script, If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
// This script should always run even when the value is empty to reset assignment group to empty
if (isLoading || newValue == '') {
g_form.setValue('ass_group', ''); // Reset the assignment group if CI is cleared
return;
}
// Use getReference to retrieve the 'cmdb_ci' record asynchronously
g_form.getReference('cmdb_ci', function(ci) {
// Check if CI's support group is set
var group = g_form.getValue('ass_group');
var category = g_form.getValue('category');
// If no assignment group is set, set it to the support group of the CI
if (group == '') {
g_form.setValue('ass_group', ci.support_group);
}
// Special condition for a certain assignment group
else if (group == '5ca69d10c370b550474c223599013190') {
alert('Dear ServiceDesk team. Please consider "Process_ServiceNow assignment" group is not a real group.');
}
Regards,
Simran