Auto-fill Assignment Group if it has only one choice based on the Assigned To

Igor Tsalyuk
Kilo Guru

Currently, I have an Assignment Group choice list reference qualifier based on the Assigned to filed. If the Assigned to field is not empty then the Assignment Group choice list only displays the list of groups the user belongs to. It works great. I would like to auto-fill the assignment group if this list only has one value. In other words, if Assigned To only belongs to one group, I would like to auto-fill this group as an Assignment Group. Any suggestions how to get this done?

1 ACCEPTED SOLUTION

Thank you, Tera Guru. This is not quite the solution I am looking for. That solution is on the server side using a business rule. Assignment Group, in our case, is a required field, so it needs to be filled out before saving the incident. The solution needed by using the client script and script includes. I was able to get it working using the following onChange client script that is triggered on table incident and field "Assigned To":

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
 
   //Call script include
var user = newValue;
var ga = new GlideAjax('global.SingleAssignmentGroup');   //Scriptinclude
ga.addParam('sysparm_name', 'getUserGroup'); //Method
ga.addParam('userId',user); //Parameters
ga.getXMLAnswer(getResponse);
 
function getResponse(response){
if (response){
g_form.setValue('assignment_group',response);
}
}
   
}
 
-----------------
 
This script triggers the following script includes:
var SingleAssignmentGroup = Class.create();
SingleAssignmentGroup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getUserGroup: function() {
var user_sys_id = this.getParameter('userId');
var userGrMember = new GlideRecord('sys_user_grmember');
userGrMember.addQuery('user', user_sys_id);
userGrMember.addQuery('group.active', true);
        userGrMember.addEncodedQuery('group.typeLIKE1cb8ab9bff500200158bffffffffff62');
        userGrMember.query();
 
if (userGrMember.getRowCount() == 1){
return userGrMember.next().group;
}
    },
    type: 'SingleAssignmentGroup'
});

View solution in original post

2 REPLIES 2

Thank you, Tera Guru. This is not quite the solution I am looking for. That solution is on the server side using a business rule. Assignment Group, in our case, is a required field, so it needs to be filled out before saving the incident. The solution needed by using the client script and script includes. I was able to get it working using the following onChange client script that is triggered on table incident and field "Assigned To":

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
 
   //Call script include
var user = newValue;
var ga = new GlideAjax('global.SingleAssignmentGroup');   //Scriptinclude
ga.addParam('sysparm_name', 'getUserGroup'); //Method
ga.addParam('userId',user); //Parameters
ga.getXMLAnswer(getResponse);
 
function getResponse(response){
if (response){
g_form.setValue('assignment_group',response);
}
}
   
}
 
-----------------
 
This script triggers the following script includes:
var SingleAssignmentGroup = Class.create();
SingleAssignmentGroup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getUserGroup: function() {
var user_sys_id = this.getParameter('userId');
var userGrMember = new GlideRecord('sys_user_grmember');
userGrMember.addQuery('user', user_sys_id);
userGrMember.addQuery('group.active', true);
        userGrMember.addEncodedQuery('group.typeLIKE1cb8ab9bff500200158bffffffffff62');
        userGrMember.query();
 
if (userGrMember.getRowCount() == 1){
return userGrMember.next().group;
}
    },
    type: 'SingleAssignmentGroup'
});