Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Reassign Tasks When Assigned User Is Inactive

Automatically detect and reassign open tasks like incidents, changes, etc. when the currently assigned user becomes inactive.

Use Case Scenario
Fetch all inactive users active = false.

For each inactive user:

Find all open tasks assigned to them.

If a manager exists - reassign tasks to that manager.

If not - assign tasks to a default support group.

Add a work note explaining the automatic reassignment.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
(function() {

var reassignedCount = 0;
var userGR = new GlideRecord('sys_user');
userGR.addQuery('active', false); // inactive users only
userGR.query();

while (userGR.next()) {
var inactiveUser = userGR.getDisplayValue('name');
var manager = userGR.manager; // reference field

// Reassign incidents
var taskGR = new GlideRecord('task');
taskGR.addQuery('assigned_to', userGR.sys_id);
taskGR.addQuery('state', '!=', 3); // not closed
taskGR.query();

var taskCount = 0;
while (taskGR.next()) {
taskCount++;

if (manager) {
taskGR.assigned_to = manager; // assign to manager
} else {
taskGR.assignment_group = 'Any_Group_Sys_ID'; // fallback
taskGR.assigned_to = ''; // clear user field
}

taskGR.work_notes = "Auto reassigned because previous assignee (" + inactiveUser + ") is inactive.";
taskGR.update();
}

if (taskCount > 0) {
reassignedCount += taskCount;
gs.info("Reassigned " + taskCount + " tasks from inactive user: " + inactiveUser);
}
}
//gs.info("Total tasks reassigned: " + reassignedCount);

})();
Loading