- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2019 06:08 AM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2019 09:19 AM
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:
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2019 06:10 AM
Sounds like you could do this with a business rule on the sys_user_grmember table. Would you only want to do it for active tasks?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2019 06:14 AM
Yes Steve, it should apply for all active tasks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2019 06:14 AM
You can write an after update business rule on "sys_user_grmember" table, whenever a user removed from that table, capture the user who was removed, glide into the table where the assigned to field needs to be cleared out, let's say incident and clear it out.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2019 06:16 AM
Hi Nitesh, I am new to developing and I did find a rule but I am not sure what I am doing wrong. Here is what I found;
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var objUserMember = new GlideRecord('sys_user_grmember');
objUserMember.addQuery('user',current.assigned_to);
objUserMember.addQuery('group',current.assignment_group);
objUserMember.query();
gs.log("Clear:Display: "+objUserMember.getRowCount().toString().length);
if(!objUserMember.next())
current.assigned_to = '';
//gs.addInfoMessage("Assigned to Cleared user not in group");
current.update();
})(current, previous);