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:56 AM
Hello @Arun Priya ,
Use the below script:
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);
}
}
}
Please mark it as correct if this helps you.
Regards,
Debasis
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2025 02:57 AM
try this
/*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 ci = 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);
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2025 04:09 AM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2025 02:58 AM
- Replace ass_group with group on line 16 since group holds the value of g_form.getValue('ass_group').
- Additionally, there’s another issue: ci.sup_group should be ci.support_group since in your previous references, support_group is the correct field name.
Below is the updated code:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
// Allow the script to run even when the value is empty
if (isLoading) {
return;
}
// Get reference for Configuration Item
g_form.getReference('cmdb_ci', setAssignGrp);
}
function setAssignGrp(ci) {
if (!ci) return; // Exit if there's no CI data
var group = g_form.getValue('ass_group'); // Get current assignment group
var category = g_form.getValue('category');
// If assignment group is empty, set it to CI's support group
if (!group) {
g_form.setValue("ass_group", ci.support_group);
}
// Alert for specific assignment group
else if (group === '5ca69d10c370b550474c223599013190') {
alert('Dear ServiceDesk team, the "Process_ServiceNow assignment" group is not a real group.');
}
// Check if assignment group should be overwritten
if (group && ci.support_group && category !== 'it') {
var answer = confirm("Do you want to overwrite the current assignment group set?");
if (answer) {
g_form.setValue("ass_group", ci.support_group);
}
}
}
Please mark correct/helpful if this helps you, thanks!