Set Assignment Group based on Configuration Item

KSaxon
Kilo Contributor

Below is the script I've adapted to allow Service Now to autofill the assignment_group field when a user types in a config item. It reads the support_group field in the cmdb_ci table. It needs to work in the following ways:

1. Only when the assignment group is already blank.
2. Only when there is a support group listed.
3. Only when the support group itself is active.

It's the third one that's giving me trouble. Currently, this code will put an inactive group into the assigment_group field if that's what the configuration item lists in its support_group field. This would be a disaster for incident management because we'd have live incidents being put into dead queues that no-one is monitoring.

Can anyone suggest a way to make Service Now only fill in the assignment_group field if the support group is active?



function onChange(control, oldValue, newValue, isLoading) {
if (isLoading)
return;

var g = g_form.getValue('assignment_group');
if (g != '') {
return;
}

if (!g_form.getControl('assignment_group'))
return;

var config = g_form.getReference('cmdb_ci', setGroup);
}

function setGroup(config) {
if (config)
g_form.setValue('assignment_group', config.support_group);
}

10 REPLIES 10

In your Catalog Task activity where you create the task in the Workflow, select the "Advanced" checkbox in the Script section and add the following code into the Advanced script field:

(function(){
	//assign the Catalog Task to the CI's Support group
	task.assignment_group = current.variables.server.support_group.toString();
	//and assign it to the Default assignee, if set
	task.assigned_to = task.assignment_group.default_assignee.toString();
})();

That will set both the Assignment group on the Catalog Task as well as assign it to a particular person if the group's Default assignee field is populated.  I usually add the Default assignee code to take advantage of the field.

You should then end up with something similar to below if the Support group and Default assignee fields are populated on your CI and Group records:

find_real_file.png