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

Jim Coyne
Kilo Patron

There's updated code in a reply of mine below that takes advantage of the displayValue parameter in the g_form.setValue() method for improved performance.

You need 2 parts for this to work properly, your Client Script and a Script Include

Client Script:



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(parseAnswer);

function parseAnswer(answer) {
g_form.setValue("assignment_group", answer);
}
}



And the Script Include:


Name: u_incidentFunctions
Active: checked
Client callable: checked
Script:

var u_incidentFunctions = Class.create();
u_incidentFunctions.prototype = Object.extendsObject(AbstractAjaxProcessor, {
u_getActiveGroup: function() {
var groupId = "";
var gr = new GlideRecord("cmdb_ci");
if (gr.get(this.getParameter("sysparm_ci"))) {
if (gr.support_group.active == true) {
groupId = gr.getValue("support_group");
}
}
return groupId;
}

});



The client script will call the Ajax function that runs on the server then returns the sys_id of the group, but only if it is currently active.

 

Hello Jim,



I am working on similar requirement and need to filter the groups in Assignment group field according to the value in Assigned to.



If a user has 5 groups, setValue() will not work as I Need to have those 5 groups in the lookup filter.



Can you let me know how can I Solve this issue.



Thanks


i want to display 2-groups only in assignment group based on catalog item




how can i fix it.....i have created 2-groups , for one item...so when that item will order assignment group should display 2-groups only


I'm getting



alert(ga.getXML()); == undefined when i try to print it out ...


am I missing something here, I have an identical setup ... but im using assignment_group not support_group.



Best,




function onChange(control, oldValue, newValue, isLoading) {


    if (isLoading || newValue == '' || g_form.getValue("assignment_group") != "") {


          alert("bail");


  return;


    }




    //Type appropriate comment here, and begin script below



alert("calling");



var ga = new GlideAjax("u_incidentFunctions");


ga.addParam("sysparm_name","u_getActiveGroup");  


    ga.addParam("sysparm_ci",newValue.toString());


alert(ga);


alert(ga.getXML());


    ga.getXMLAnswer(parseAnswer);  


     


alert("finished");



    function parseAnswer(answer) {  


  alert("perf action");


  alert(answer);


          g_form.setValue("assignment_group", answer);  


    }  



   


}



that's the client script


the script include is a copy/paste of yours.