From 5ecb3b7438fed07151570f61ffe40fc4971aa342 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 17 Oct 2025 07:35:35 -0700 Subject: [PATCH] tested and working. script for timezone bulk updates --- .../Bulk Update User Time Zones/README.md | 9 +++++++ .../Bulk Update User Time Zones/script.js | 27 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 Specialized Areas/Fix scripts/Bulk Update User Time Zones/README.md create mode 100644 Specialized Areas/Fix scripts/Bulk Update User Time Zones/script.js diff --git a/Specialized Areas/Fix scripts/Bulk Update User Time Zones/README.md b/Specialized Areas/Fix scripts/Bulk Update User Time Zones/README.md new file mode 100644 index 0000000000..bbc9f6bb68 --- /dev/null +++ b/Specialized Areas/Fix scripts/Bulk Update User Time Zones/README.md @@ -0,0 +1,9 @@ +# Bulk Update User Time Zones + +This background script updates the time zone for all users in a specified group. + +## Usage + +1. Set the `GROUP_SYS_ID` and `NEW_TIME_ZONE` variables in the script. +2. Run the script in the ServiceNow Background Scripts module. +3. The script will update the `time_zone` field for all users in the group. \ No newline at end of file diff --git a/Specialized Areas/Fix scripts/Bulk Update User Time Zones/script.js b/Specialized Areas/Fix scripts/Bulk Update User Time Zones/script.js new file mode 100644 index 0000000000..3ded7cebc3 --- /dev/null +++ b/Specialized Areas/Fix scripts/Bulk Update User Time Zones/script.js @@ -0,0 +1,27 @@ +// Bulk update user time zones for all users in a specific group + +var GROUP_SYS_ID = 'PUT_GROUP_SYS_ID_HERE'; // Your group sys_id +var NEW_TIME_ZONE = 'Pacific/Auckland'; // e.g., 'America/Chicago', 'Europe/London' + +// Get group members +var group = new GlideRecord('sys_user_group'); +var grMembers = new GlideRecord('sys_user_grmember'); +grMembers.addQuery('group', GROUP_SYS_ID); +grMembers.query(); + +var count = 0; +while (grMembers.next()) { + var user = new GlideRecord('sys_user'); + if (user.get(grMembers.user)) { + + // Only update if timezone is different + if (user.time_zone != NEW_TIME_ZONE) { + var oldTz = user.time_zone; + user.time_zone = NEW_TIME_ZONE; + user.update(); + count++; + } + } +} + +gs.info('Updated time zone for ' + count + ' users in group "' + GROUP_SYS_ID + '"'); \ No newline at end of file