Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Assignment groups, groups for roles.... why such confuse?

Brendan Hallida
Kilo Guru

Hi all,

Just want to start in saying that this could be me confusing myself!

From what I can gather - the best way to assign roles is to assign to groups, and then add the users to those groups.

This is fine and dandy - however we do not want to have these groups as assignment groups.

I followed the below wiki article, and assigned the group type as 'itil' and then modified the Assignment group's dictionary entry to contain type 'itil'

Configuring Group Types for Assignment Groups - ServiceNow Wiki

find_real_file.png

find_real_file.png

This works great, and as expected, until someone who is a member of more than one group.

What we have found is if you were to add an assignee in Assigned to before adding an assignment group, it will add the first group they are a member of, whether or not it is an assignment group with the 'itil' type or not.

Does anyone know how I can stop this from happening?

I hope I have explained this well enough......

Thanks in Advance!

Brendan

1 ACCEPTED SOLUTION

Hello Brendan,



Replace gr.group.type with group.type


View solution in original post

20 REPLIES 20

So I think that I have found the sys id, 3D1cb8ab9bff500200158bffffffffff62



find_real_file.png



This is the code that I am using in the script includes (line 39 is your addition):



var KSTaskAjax = Class.create();




KSTaskAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {


});




KSTaskAjax.prototype.checkTaskSLABreached = function() {


  return String(KSTaskUtil.isResolveSLABreached(this.getParameter('sysparm_sysID')));


};




// finds a group to default for the current assigned to person


// just picks the first group; user needs to check this before saving


KSTaskAjax.prototype.getPrimaryGroupInfo = function() {



  var assignedTo = this.getParameter('sysparm_assignedTo');



  var retObj = {};


  retObj.groupID = '';


  retObj.groupName = '';


  retObj.assignedName = '';


  retObj.groupCount = 0;


  if (assignedTo != '') {


  //


  // Get the user record


  //


  var userRec = new GlideRecord('sys_user');


  if (userRec.get(assignedTo)) {


  retObj.assignedName = userRec.name.toString();


  //


  // count how many active assignment groups the assigned to belongs to.


  // only allow groups: with no type set (signifies assignment group)


  //                                   : that are active


  //


  var memberRec = new GlideRecord('sys_user_grmember');


  memberRec.addQuery('user', assignedTo);


  memberRec.addQuery('group.active', 'true');


  memberRec.addQuery('gr.group.type', '3D1cb8ab9bff500200158bffffffffff62');


  memberRec.addNullQuery('group.type');


  memberRec.query();


  while (memberRec.next()) {


  //


  // return the first assignment group encountered to auto populate the group on the task record


  //


  if (retObj.groupCount == 0) {


  if (retObj.groupID == '') {


  retObj.groupID       = memberRec.group.toString();


  retObj.groupName   = memberRec.group.name.toString();


  }


  }


  retObj.groupCount++;


  }


  }


  }



  var json = new JSON();


  var returnData = json.encode(retObj);


  return returnData;


};



However after these changes, it is not only filtering assignment groups to the ITIL type: (Report Administrators does not have the ITIL type)



find_real_file.png



Am i missing something?


Hello Brendan,



Replace gr.group.type with group.type


Hey Pradeep,



That worked, well sort of.



At first when changing it - I got the error:


find_real_file.png



In the script, under the line we added was the following:


memberRec.addNullQuery('group.type');



When I commented this out - the auto backfill worked successfully!



My question to you is - Do you think that it is ok to leave the line out of the script?   I have been testing, and all seems ok, but just wanted to make sure


Hello Brendan,



Thanks for the update. Basically, addNullQuery here returns the record where group.type is null.


In case you don't want this then you can comment it.


https://wiki.servicenow.com/index.php?title=GlideRecord#addNullQuery&gsc.tab=0


awesome Pradeep, thanks again for your help