Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Specialized Areas/Fix scripts/Mass Email Domain Update/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Update User Email Domain in ServiceNow

This script finds all users in the **`sys_user`** table whose email addresses contain an old domain (e.g. `bad_domain.com`) and replaces it with a new domain (e.g. `new_domain.com`) using **regular expressions**.

---

## Purpose

To bulk–update user email domains safely and efficiently without manual edits.

Example use case:
When your organization migrates from `@bad_domain.com` to `@new_domain.com`, this script updates all users automatically.

---

## Example
| Old Email | New Email |
|-------------------------|------------------------|
| alice@bad_domain.com | alice@new_domain.com |
| bob@bad_domain.com | bob@new_domain.com |
| carol@bad_domain.com | carol@new_domain.com |

17 changes: 17 additions & 0 deletions Specialized Areas/Fix scripts/Mass Email Domain Update/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Use: Fix script to update all email domains in sys_user table
// Replaces 'bad_domain.com' with 'new_domain.com' in email field

var usr = new GlideRecord('sys_user');
usr.addEncodedQuery('emailLIKEbad_domain.com'); // find users with old domain
usr.query();

while (usr.next()) {
gs.print('OLD EMAIL: ' + usr.email);

// Create regex to match old domain
var regex = new SNC.Regex('bad_domain\\.com'); // uses '\\' to escape dot for regex
// Use replaceAll method to substitute
usr.email = regex.replaceAll(usr.email, 'new_domain.com');
usr.update();
gs.print('NEW EMAIL: ' + usr.email);
}
Loading