Skip to content
Merged
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
## Reassignment of Manager from Group and User Tables to New Manager for Outgoing/Retiring Manager

Automatically reassigns all groups and users managed by a retiring manager to a new manager and deactivates the outgoing manager’s **sys_user** record.

- Ensures transition by updating manager references in both user and group tables before disabling the old manager’s access.
- Uses a Background Script to perform the following actions:
- Updates all groups where the old manager is assigned
- Updates all users reporting to the old manager by new manager
- Make old manager’s user record inactive in **sys_user** record

### Prerequisites :
- Keep old manager's and new manager's sys_ids ready
- Navigate to System Definition → Scripts - Background
- Click New and paste the script. In the script Replace with your requirement:
- var oldManagerSysId = `<Include sys id of old Manager >`
- var newManagerSysId = `<Include sys id of New Manager >`
- Run Script

---

### Example Of Group Table Record Before Script Execution

![Manager Reassignment](BackGroundScript_UpdateManager_Replace_2.png)

---

### Background Script Execution

![Manager Reassignment](BackGroundScript_UpdateManager_Replace_3.png)

---

### Example Of Group Table Record After Script Execution

![Manager Reassignment](BackGroundScript_UpdateManager_Replace_4.png)

---
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
var oldManagerSysId = '506c0f9cd7011200f2d224837e61030f'; // <Include sys id of old Manager >
var newManagerSysId = '46c6f9efa9fe198101ddf5eed9adf6e7'; // <Include sys id of New Manager >

gs.print('========== MANAGER REASSIGNMENT FROM GROUP, USERS AND DEACTIVATE RETIRING MANAGER USER ID ==========');

// --- STEP 1: Update Groups managed by old manager ---
var grpCount = 0;
var grpGR = new GlideRecord('sys_user_group');
grpGR.addQuery('manager', oldManagerSysId);
grpGR.query();

gs.print('Checking groups managed by retiring manager...');
while (grpGR.next()) {
gs.print('➡️ Group: ' + grpGR.name + ' | Old Manager: ' + grpGR.manager.getDisplayValue());

grpGR.manager = newManagerSysId;
grpGR.update();
gs.print('✅ Group manager updated ');

grpCount++;
}
gs.print('Total groups updated: ' + grpCount);

// --- STEP 2: Update Users reporting to old manager ---
var userCount = 0;
var userGR = new GlideRecord('sys_user');
userGR.addQuery('manager', oldManagerSysId);
userGR.query();

gs.print('\ Checking users reporting to retiring manager...');
while (userGR.next()) {
gs.print('👤 User: ' + userGR.getDisplayValue('name') + ' | Current Manager: ' + userGR.manager.getDisplayValue());
userGR.manager = newManagerSysId;
userGR.update();
gs.print('✅ User manager updated ');
userCount++;
}
gs.print('Total users updated: ' + userCount);

// --- STEP 3: Deactivate old manager ---
var mgrGR = new GlideRecord('sys_user');
if (mgrGR.get(oldManagerSysId)) {
gs.print('\n Retiring Manager: ' + mgrGR.getDisplayValue('name'));
mgrGR.active = false;
mgrGR.locked_out = true; // optional – prevents login
mgrGR.update();
gs.print('✅ Old manager deactivated and locked out.');
} else {
gs.print(' Could not find old manager record.');
}

gs.print('\n========== PROCESS COMPLETE ==========');
Loading