Clear out assigned to field when assigned user is removed from assignment group

Tee Fortune
Kilo Explorer

Hello everyone,

I am looking to have the assigned to field cleared out automatically if the assigned to user is removed from the group. What would be the best way to go about this please? 

1 ACCEPTED SOLUTION

Jim Coyne
Kilo Patron

OK, let's take a step back for a moment and simplify things.

You want to remove the user from the "Assigned to" field on any active, Task-derived record when the user is removed from a group, correct?  So we need to look at all Task records where "Active" is true, the "Assignment group" is the Group the User was just removed from and the "Assigned to" field is the removed user.

To do that, we want to create a new "Advanced", "After Delete" Business Rule on the Group Member table:

find_real_file.png

So this BR will only trigger whenever a User is removed from a Group.

Here's the code you can use in the Script field:

(function executeRule(current, previous /*null when async*/) {
	var groupId = current.getValue("group");
	var groupName = current.group.getDisplayValue();
	var userId = current.getValue("user");
	var userName = current.user.getDisplayValue();

	//look for all Active Task records assigned to the Group AND User
	var gr = new GlideRecord("task");
	gr.addEncodedQuery("active=true^assignment_group=" + groupId + "^assigned_to=" + userId);
	gr.query();
	while (gr.next()) {
		//add a work note to let people know why the field was cleared
		gr.work_notes.setJournalEntry("Assigned to field cleared because '" + userName + "' was removed from the current Assignment group '" + groupName + "'");
		gr.assigned_to = "";
		gr.update();
	}
})(current, previous);

View solution in original post

26 REPLIES 26

if its the task table, replace "incident" with "task"

Assigned to cleared out only when the incident was updated. I also replaced incident with task in the script and had the same result. 

 

find_real_file.png

find_real_file.png

 

 

find_real_file.png

how are you testing this? by removing a user from a group and checking all the records he existed with the same assignment group?

Yes Nitesh, I removed the user from assignment group-> rechecked incident and the user did not clear out of the assigned to field.  I had to make an update to the ticket priority for the cleared out action to trigger.

you might have to put a few log statements to check what's working and what's not working, also double check the field names with the field names on the script.