Need to change Manager of almost 50 users

Vyanktesh08
Tera Contributor

Hello Team,

 

I need to change the manager of Almost 50 users , How Can I achieve this by using Background script

 

Thanks In advance. 

7 REPLIES 7

SP22
Giga Sage
Giga Sage

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.  

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
-Anurag

Sohail Khilji
Kilo Patron
Kilo Patron

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....

LinkedIn - Lets Connect