From 7e116f1edd0b62050abef0317f5ddaa749ec108b Mon Sep 17 00:00:00 2001 From: DhruvBhatheja <70469942+DhruvBhatheja@users.noreply.github.com> Date: Tue, 14 Oct 2025 10:23:38 +0530 Subject: [PATCH 1/2] script.js --- .../script.js | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Server-Side Components/Background Scripts/Reassign Tasks When Assigned User Is Inactive/script.js diff --git a/Server-Side Components/Background Scripts/Reassign Tasks When Assigned User Is Inactive/script.js b/Server-Side Components/Background Scripts/Reassign Tasks When Assigned User Is Inactive/script.js new file mode 100644 index 0000000000..c3334bcd02 --- /dev/null +++ b/Server-Side Components/Background Scripts/Reassign Tasks When Assigned User Is Inactive/script.js @@ -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); + +})(); From 9c89e0498eb020572e79f127047f2129b0d9f520 Mon Sep 17 00:00:00 2001 From: DhruvBhatheja <70469942+DhruvBhatheja@users.noreply.github.com> Date: Tue, 14 Oct 2025 10:27:17 +0530 Subject: [PATCH 2/2] Readme.md --- .../Readme.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Server-Side Components/Background Scripts/Reassign Tasks When Assigned User Is Inactive/Readme.md diff --git a/Server-Side Components/Background Scripts/Reassign Tasks When Assigned User Is Inactive/Readme.md b/Server-Side Components/Background Scripts/Reassign Tasks When Assigned User Is Inactive/Readme.md new file mode 100644 index 0000000000..2373ba0890 --- /dev/null +++ b/Server-Side Components/Background Scripts/Reassign Tasks When Assigned User Is Inactive/Readme.md @@ -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.