Filter Assignment Group based on Assigned To

ericblanks
Tera Contributor

Occasionally we will assign an Incident, Problem, Change to the Assigned To prior to choosing an Assignment Group.   Once the Assigned To is populated I would like to filter the Assignment Group list to include only Groups that the Assigned To is a member of.   Can anyone help me with the code for such a request?

6 REPLIES 6

Jaspal Singh
Mega Patron
Mega Patron

Hi Eric,



Link Populate assignment group based on assigned to   should help.


paolasalcido
Kilo Guru

Hi Eric,



You can obtain the groups depending on the user or in this case depending on the assigned to user



var assignedUsr= gs.getUser();


assignedUsr= assignedUsr. ­getUserByID( ­sys_id);


assignedUsr.getMyGroups()


ericblanks
Tera Contributor

I followed the link posted above with failing results.   There are two articles, one says to add the code to a script include, the other link says to add it to a business rule.   I've tried both.   Neither is working for me.   Can anyone break it down into high level steps I need to follow.   I'm not a trained java scripter so I'm just copying scripts, I don't actually know what they do.  



Thanks again for all the help.


The following should work for what you need. Build out the following script include and add the reference in the reference qualifier in the assignment group field.



Script include: filterAssignmentGroups


// -------------------------------------------------


// Reference: Group


// Use Reference Qualifier: Advanced


// Reference qual: javascript:filterAssignmentGroups(current.sys_class_name, current.assigned_to);


// --------------------------------------------------


function filterAssignmentGroups(table,assignee){


  var string = "sys_idIN";


  if(assignee == ""){


    var gr = new GlideRecord("sys_user_group");


    gr.addQuery("active",true);


    gr.query();


    while(gr.next()){


      string += gr.sys_id + ",";


    }


   


  } else {


    var grmem = new GlideRecord("sys_user_grmember");


    grmem.addQuery("user", assignee);


    grmem.query();


    while(grmem.next()){


      var grLook = new GlideRecord("sys_user_group");


      grLook.addQuery("sys_id",grmem.group);


      grLook.addQuery("active",true);


      grLook.query();


      while(grLook.next()){


        string += grLook.sys_id + ",";


      }


    }


  }


  return string;


}



High Level:


1. Create Script Include.


2. Paste Above Script in the include.


3. Right click on the assignment group field.


4. Set fields as follows:



find_real_file.png