Bulk Changing Users Email Domain

Ben Billingham
Kilo Contributor

Hello,

I'm currently working on an email domain migration project and I'm looking into how I can change all the users on ServiceNow in bulk. I have searched around for a way to bulk update users but I cannot find anything. Before I go ahead and change all the users manually I thought I'd ask on here for some advice. If you know of a way to bulk change users email domain on ServiceNow I would really appreciate the knowledge.

 

For example I'd like to take all the users who are like so:

John.Doe@old.com

And change them all to a different domain like so:

John.Doe@new.com

 

Thanks, Ben

3 REPLIES 3

Tony Chatfield1
Kilo Patron

Hi, I think the domain change is fairly simple via a background script to update sys_user and also cmn_notif_device records

But if you use email address as 'user_name' you should also assess for any function where you reference sys_created_by or sys_updated_by fields, as there could be impact as these will no longer match the user.

For the update find matching records, iterate through them and for each record grab anything before ‘@’ using substring and indexOf

  • lastIndexOf if your data contains multiple @ (which is not common for email addresses but I think I read somewhere that it was valid)

something like (untested)

var userUpdate = new GlideRecord(‘sys_user’);
userUpdate.addEncodedQuery(‘emailENDSWITH@example.com’);
userUpdate.query();

while(userUpdate.next())

{

userEmail = userUpdate.email;
userName = userEmail.substring(0, userEmail.indexOf('@') );

userUpdate.email = userName + 'yourNewDomain';

//I'd also add some logging, just incase


userUpdate.update();

}

Ben Billingham
Kilo Contributor

Hello Tony,

Thanks for your advice it seems fairly easy to do but I have a few more questions. We're doing a batch migration so ideally I need to change ServiceNow email domains for a specific set of users. From what I gather ServiceNow background scripts use Java? Would I therefore be able to use FileInputStream to view an Excel spreadsheet and only change the email domain for the users in that spreadsheet?

Thanks, Ben 

Did u got any update on this?