Skip to content

Commit 96ad81c

Browse files
authored
Reassignment of Manager from Group and User Tables to New Manager for Outgoing/Retiring Manager (#2515)
* Create README.md * Add files via upload * Create backgroundScriptManagerReassign.js * Update README.md updated readme
1 parent 6a22379 commit 96ad81c

File tree

5 files changed

+89
-0
lines changed

5 files changed

+89
-0
lines changed
Loading
Loading
Loading
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
## Reassignment of Manager from Group and User Tables to New Manager for Outgoing/Retiring Manager
2+
3+
Automatically reassigns all groups and users managed by a retiring manager to a new manager and deactivates the outgoing manager’s **sys_user** record.
4+
5+
- Ensures transition by updating manager references in both user and group tables before disabling the old manager’s access.
6+
- Uses a Background Script to perform the following actions:
7+
- Updates all groups where the old manager is assigned
8+
- Updates all users reporting to the old manager by new manager
9+
- Make old manager’s user record inactive in **sys_user** record
10+
11+
### Prerequisites :
12+
- Keep old manager's and new manager's sys_ids ready
13+
- Navigate to System Definition → Scripts - Background
14+
- Click New and paste the script. In the script Replace with your requirement:
15+
- var oldManagerSysId = `<Include sys id of old Manager >`
16+
- var newManagerSysId = `<Include sys id of New Manager >`
17+
- Run Script
18+
19+
---
20+
21+
### Example Of Group Table Record Before Script Execution
22+
23+
![Manager Reassignment](BackGroundScript_UpdateManager_Replace_2.png)
24+
25+
---
26+
27+
### Background Script Execution
28+
29+
![Manager Reassignment](BackGroundScript_UpdateManager_Replace_3.png)
30+
31+
---
32+
33+
### Example Of Group Table Record After Script Execution
34+
35+
![Manager Reassignment](BackGroundScript_UpdateManager_Replace_4.png)
36+
37+
---
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
var oldManagerSysId = '506c0f9cd7011200f2d224837e61030f'; // <Include sys id of old Manager >
2+
var newManagerSysId = '46c6f9efa9fe198101ddf5eed9adf6e7'; // <Include sys id of New Manager >
3+
4+
gs.print('========== MANAGER REASSIGNMENT FROM GROUP, USERS AND DEACTIVATE RETIRING MANAGER USER ID ==========');
5+
6+
// --- STEP 1: Update Groups managed by old manager ---
7+
var grpCount = 0;
8+
var grpGR = new GlideRecord('sys_user_group');
9+
grpGR.addQuery('manager', oldManagerSysId);
10+
grpGR.query();
11+
12+
gs.print('Checking groups managed by retiring manager...');
13+
while (grpGR.next()) {
14+
gs.print('➡️ Group: ' + grpGR.name + ' | Old Manager: ' + grpGR.manager.getDisplayValue());
15+
16+
grpGR.manager = newManagerSysId;
17+
grpGR.update();
18+
gs.print('✅ Group manager updated ');
19+
20+
grpCount++;
21+
}
22+
gs.print('Total groups updated: ' + grpCount);
23+
24+
// --- STEP 2: Update Users reporting to old manager ---
25+
var userCount = 0;
26+
var userGR = new GlideRecord('sys_user');
27+
userGR.addQuery('manager', oldManagerSysId);
28+
userGR.query();
29+
30+
gs.print('\ Checking users reporting to retiring manager...');
31+
while (userGR.next()) {
32+
gs.print('👤 User: ' + userGR.getDisplayValue('name') + ' | Current Manager: ' + userGR.manager.getDisplayValue());
33+
userGR.manager = newManagerSysId;
34+
userGR.update();
35+
gs.print('✅ User manager updated ');
36+
userCount++;
37+
}
38+
gs.print('Total users updated: ' + userCount);
39+
40+
// --- STEP 3: Deactivate old manager ---
41+
var mgrGR = new GlideRecord('sys_user');
42+
if (mgrGR.get(oldManagerSysId)) {
43+
gs.print('\n Retiring Manager: ' + mgrGR.getDisplayValue('name'));
44+
mgrGR.active = false;
45+
mgrGR.locked_out = true; // optional – prevents login
46+
mgrGR.update();
47+
gs.print('✅ Old manager deactivated and locked out.');
48+
} else {
49+
gs.print(' Could not find old manager record.');
50+
}
51+
52+
gs.print('\n========== PROCESS COMPLETE ==========');

0 commit comments

Comments
 (0)