Auto-populate/Filter assignment group based on Assigned to

VernYerem
Tera Expert

Good afternoon!

 

Our org is having an issue where someone knows the individual that a task should be Assigned to, but not their group. Currently our assignment group will filter the assigned to so that it'll only search for it's users (Easy dependency). But we're looking for something similar in the other direction and want to retain this.

 

Desired result:

Select a user in "Assigned to", then the assignment group will apply the group they are a member of. If the user is part of multiple groups, filter the list of groups to only be that user's groups similar to above and don't populate the value to allow the technician to select the correct group for the task.

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron
4 REPLIES 4

Periyasamy P
Tera Guru

Change assignment group reference qualifier to advance and add to script to handle this use case.

For ex,
if (gs.nil(current.assigned_to)){
   return "active=true";
} else {
  //glide user groups and retrun group sys_ids
  return "sys_idIN"+<sys_id>
}

 

Sandeep Rajput
Tera Patron
Tera Patron

@VernYerem Please refer to this thread https://www.servicenow.com/community/developer-forum/how-to-add-ref-qualifier-to-backfill-assignment... where the similar implementation has been suggested.

Oh that's close!

 

So, the script include is:

var BackfillAssignmentGroup = Class.create();
BackfillAssignmentGroup.prototype = {
    initialize: function() {
    },
	  // Filter out groups that are not the provided type
   filterGroupsonUser: function(cUser) {
	   
		var gp = ' ';
		var a = cUser;
		//return everything if the assigned_to value is empty
		if(!cUser)
		return;
		 
		//sys_user_grmember has the user to group relationship
		var grp = new GlideRecord('sys_user_grmember');
		grp.addQuery('user',cUser);
		grp.query();
	   
		while(grp.next()) {
			
			if (gp.length > 0) {
					//build a comma separated string of groups if there is more than one
					gp += (',' + grp.group);
					
			}
			else {
					gp = grp.group;
					
			}
		}
	return 'sys_idIN' + gp;
	// return Groups where assigned to is in those groups we use IN for lists
   
	   
   },

	type: 'BackfillAssignmentGroup'
}

 

We have a current simple qualifier of: Type - Contains - ITIL
I tried to add the call to the script include in the advanced reference qual but it didn't seem to work:

typeLIKE1cb8ab9bff500200158bffffffffff62^javascript&colon;new BackfillAssignmentGroup().filterGroupsonUser(current.assigned_to);

I assume I need to add the type in the script somewhere.

Oh! Just needed to add the "typeLIKE" into the return of the script.

return 'sys_idIN' + gp + '^typeLIKE1cb8ab9bff500200158bffffffffff62';