Need to change Manager of almost 50 users
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2024 05:42 AM
Hello Team,
I need to change the manager of Almost 50 users , How Can I achieve this by using Background script
Thanks In advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2024 05:52 AM - edited 03-26-2024 05:52 AM
Hi @Vyanktesh08
// Construct the encoded query string
var encodedQuery = 'department=Your Department^active=true';
// Query for users that need to have their manager updated
var userGr = new GlideRecord('sys_user');
userGr.addEncodedQuery(encodedQuery);
userGr.query();
// Set the new manager's user ID
var newManagerID = 'new_manager_user_id';
// Loop through the users and update their manager
while (userGr.next()) {
userGr.manager = newManagerID;
userGr.update();
gs.info('Manager updated for user ' + userGr.name);
}
Please find the above sample script and do changes as per your requirement.
Thanks
SP.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2024 05:56 AM
This is good, just to add I would add set limit to 50
Also you can use the below , if it fits your use case
gr.autoSysFields(
false
);
//do not update system fields
gr.setWorkflow(
false
);
//do not run business rules
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2024 06:01 AM
50 is a small number you can simply do it visa list view change. As suggested by @Dr Atul G- LNG
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....