How do I limit the Assignment Group field to groups the person listed in the Assigned To field is a member of?

billcravey
Kilo Contributor

On our incident form the Assignment Group field is mandatory. Once a group is entered their, only the members of that group can be selected in the Assigned to field. I would like to do this in the reverse, initially leaving the Assignment Group empty, adding a user in the Assigned To field and then under the magnifying glass for the Assignment Group field I would only see the group or groups that user is a member of. Any thoughts are appreciated.

Thanks,

Bill Cravey

HonorHealth

william.cravey@honorhealth.com

1 ACCEPTED SOLUTION

larmstrong
Tera Expert

We are currently doing this, and it works fantastically!



Here is how we make it work (we also use the same logic on other fields.   We have a set of 4 hierarchical fields where each one is limited by the field/s directly adjacent to it).



On Assigned to:


Dependent on = assignment_group



On Assignment group:


Ref qualifier is set to: javascript:BackfillAssignmentGroup()



Script for BackfillAssignmentGroup():



function BackfillAssignmentGroup(){


      var groupList = ' ';


      var assignedTo = current.assigned_to;


     


      //return all groups if the assigned_to value is empty.


      if(assignedTo == ''){


              //list of groups that have the "assignment group" type, and filter out inactive groups.


              return 'typeLIKE188225e715480200abe63ac4a19e9dfa^active=true';


      }


      //sys_user_grmember has the user to group relationship


      var grpGR = new GlideRecord('sys_user_grmember');


      grpGR.addQuery('user',assignedTo);


      grpGR.addEncodedQuery('group.typeLIKE188225e715480200abe63ac4a19e9dfa^group.active=true');


      grpGR.query();


      while(grpGR.next()) {


              if (groupList.length > 0) {


                      //build a comma separated string of groups if there is more than one


                      groupList += (',' + grpGR.group);


              }


              else {


                      groupList = grpGR.group;


              }


      }


      // return Groups where assigned to is in those groups we use IN for lists


      return 'sys_idIN' + groupList;


}



Please let me know if you have questions!



~Lindsey


View solution in original post

10 REPLIES 10

larmstrong
Tera Expert

We are currently doing this, and it works fantastically!



Here is how we make it work (we also use the same logic on other fields.   We have a set of 4 hierarchical fields where each one is limited by the field/s directly adjacent to it).



On Assigned to:


Dependent on = assignment_group



On Assignment group:


Ref qualifier is set to: javascript:BackfillAssignmentGroup()



Script for BackfillAssignmentGroup():



function BackfillAssignmentGroup(){


      var groupList = ' ';


      var assignedTo = current.assigned_to;


     


      //return all groups if the assigned_to value is empty.


      if(assignedTo == ''){


              //list of groups that have the "assignment group" type, and filter out inactive groups.


              return 'typeLIKE188225e715480200abe63ac4a19e9dfa^active=true';


      }


      //sys_user_grmember has the user to group relationship


      var grpGR = new GlideRecord('sys_user_grmember');


      grpGR.addQuery('user',assignedTo);


      grpGR.addEncodedQuery('group.typeLIKE188225e715480200abe63ac4a19e9dfa^group.active=true');


      grpGR.query();


      while(grpGR.next()) {


              if (groupList.length > 0) {


                      //build a comma separated string of groups if there is more than one


                      groupList += (',' + grpGR.group);


              }


              else {


                      groupList = grpGR.group;


              }


      }


      // return Groups where assigned to is in those groups we use IN for lists


      return 'sys_idIN' + groupList;


}



Please let me know if you have questions!



~Lindsey


Thank you. I am very new to SN and particularly java scripting. The first couple of steps on your instructions are simple but after that I don't know where to create this java script. I appreciate your assistance.


Create a script include and put the script there.



If you do not use "group type" on your groups, it may not return anything.   You'll have to adjust the line that filters by that anyway to use your own sys_id for that field type.   The rest of it should work.



THe wiki will tell you how to get encoded queries and how to use glide records.   Those will become friends of yours 🙂



~L


Thank you, Lindsey. I got it to work with your help.