- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2017 12:37 PM
We have changed our email domain and now I need to update all of my users. I would like to run a script that would find all of the @olddomain.com and replace it with @newdomain.
Can anyone assist me with this?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2017 12:42 PM
Hello Phil,
Here you go. Please run this from background script. Try this on your dev instance first.
var gr = new GlideRecord('sys_user');
gr.query();
while(gr.next())
{
var str = gr.email;
var res = str.replace("@olddomain.com", "@newdomain.com");
gr.email = res;
gr.setWorkflow(false);
gr.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2017 12:42 PM
Hi Phil,
Pretty easy. Obviously, test this in dev and test before production. Try this in either Scripts Background or a Fix Script. A Fix Script will allow you to capture it in an update set and migrated to test and prod!
Standard disclaimer: The following code is untested, requires review and potential modifications.
(function () {
var rec = new GlideRecord('sys_user');
rec.addQuery('email', "ENDSWITH", '@olddomain.com');
rec.query();
while (rec.next()) {
var email = rec.getValue('email');
var newEmail = email.replace('@olddomain', '@newDomain');
rec.email = newEmail;
rec.setWorkflow(false);
rec.update();
}
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2017 11:35 AM
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2017 11:36 AM
Thanks Pradeep worked like a charm.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2017 09:43 PM
Thanks Phil for the update.
Let me know if that answered your question. If so, please mark it as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list. Thank you