File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
Specialized Areas/Fix scripts/Bulk Update User Time Zones Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ # Bulk Update User Time Zones
2+
3+ This background script updates the time zone for all users in a specified group.
4+
5+ ## Usage
6+
7+ 1 . Set the ` GROUP_SYS_ID ` and ` NEW_TIME_ZONE ` variables in the script.
8+ 2 . Run the script in the ServiceNow Background Scripts module.
9+ 3 . The script will update the ` time_zone ` field for all users in the group.
Original file line number Diff line number Diff line change 1+ // Bulk update user time zones for all users in a specific group
2+
3+ var GROUP_SYS_ID = 'PUT_GROUP_SYS_ID_HERE' ; // Your group sys_id
4+ var NEW_TIME_ZONE = 'Pacific/Auckland' ; // e.g., 'America/Chicago', 'Europe/London'
5+
6+ // Get group members
7+ var group = new GlideRecord ( 'sys_user_group' ) ;
8+ var grMembers = new GlideRecord ( 'sys_user_grmember' ) ;
9+ grMembers . addQuery ( 'group' , GROUP_SYS_ID ) ;
10+ grMembers . query ( ) ;
11+
12+ var count = 0 ;
13+ while ( grMembers . next ( ) ) {
14+ var user = new GlideRecord ( 'sys_user' ) ;
15+ if ( user . get ( grMembers . user ) ) {
16+
17+ // Only update if timezone is different
18+ if ( user . time_zone != NEW_TIME_ZONE ) {
19+ var oldTz = user . time_zone ;
20+ user . time_zone = NEW_TIME_ZONE ;
21+ user . update ( ) ;
22+ count ++ ;
23+ }
24+ }
25+ }
26+
27+ gs . info ( 'Updated time zone for ' + count + ' users in group "' + GROUP_SYS_ID + '"' ) ;
You can’t perform that action at this time.
0 commit comments