Set Assignment Group based on Configuration Item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2013 03:42 AM
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);
}
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2017 04:27 PM
Ok, I got it to work, was a mix of spelling mistakes for the most part assignment*
I have a question now, I made a user, and assigned ITIL role, this user cannot see any of the groups in the 'assignment' section. So even though the value is getting auto snapped, they can't see that assignment group, I've confirmed I can see the group auto populate as I want under an admin account -
Thoughts?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2018 08:43 PM
This answer should be updated to send both the sys_id and name of the Group back to the client from the server. This will improve performance by avoiding the need for ServiceNow to go back to get the display value when setting the value of reference field.
Updated Client Script code:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == "" || g_form.getValue("assignment_group") != "") {
return;
}
var ga = new GlideAjax("u_incidentFunctions");
ga.addParam("sysparm_name","u_getActiveGroup");
ga.addParam("sysparm_ci",newValue.toString());
ga.getXMLAnswer(u_displayData);
function u_displayData(response){
var answer = JSON.parse(response.responseXML.documentElement.getAttribute("answer")); //convert the returned JSON string to an object
g_form.setValue("assignment_group", answer.groupId, answer.groupName); //call setValue with both the sys_id and display value to avoid return call to the server
}
}
Updated Script Include code:
var u_incidentFunctions = Class.create();
u_incidentFunctions.prototype = Object.extendsObject(AbstractAjaxProcessor, {
u_getActiveGroup: function() {
var dataToReturn = {};
dataToReturn.groupId = "";
dataToReturn.groupName = "";
var sysId = this.getParameter("sysparm_ci");
if (sysId){
var gr = new GlideRecord("cmdb_ci");
if (gr.get(sysId)) {
if (gr.support_group.active == true) {
dataToReturn.groupId = gr.getValue("support_group");
dataToReturn.groupName = gr.support_group.getDisplayValue();
}
}
}
return JSON.stringify(dataToReturn); //return the object as a JSON string
},
type: "u_incidentFunctions"
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2013 01:29 AM
That's perfect, thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2015 05:43 PM
Hello Kevin,
I am trying to do the same and have tried the what Jim suggested but for some reason am still unable to get this to work. I was wondering if you could provide some hint on how you got it to work.
Thank!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2018 01:26 PM
Trying something slightly different.
1. Create a Catalog Item, that contains a Configuration item lookup field.
2. User submits, creates RITM, then the Catalog Task.
3. However the Assignment group is null, until someone opens the Catalog task,
then it calculates and autofills the Assignment Group on the Task, using a Client Script.
4. Problem is that someone has to 1st open the Catalog Task, then it autofills, then save,
or if someone changes the CI, it will also work.
There has to be a method of coding an advanced script in the workflow that if it has the Configuration Item
cmdb_ci, and then go get the assignment_group associated with the cmdb_ci. support_group.
Trying to find some code to get started, since the Client Scripts require someone to 1st open the Task, then the Assignment_group then autofills.