diff --git a/Server-Side Components/Background Scripts/Clone User with Roles and Groups/README.md b/Server-Side Components/Background Scripts/Clone User with Roles and Groups/README.md index 12aa1fba6f..4fc9000dcf 100644 --- a/Server-Side Components/Background Scripts/Clone User with Roles and Groups/README.md +++ b/Server-Side Components/Background Scripts/Clone User with Roles and Groups/README.md @@ -1,2 +1,29 @@ # Clone User with Roles and Groups -I have created a script in ServiceNow to replicate a user's profile. This script not only duplicates the user's data but also replicates the roles and groups assigned to that user. + +A background script that clones an existing user's profile including all their roles and group memberships to a new user account. + +## Usage + +1. Navigate to **System Definition → Scripts - Background** +2. Copy and paste the script content +3. Update the function call at the bottom with the source and target user IDs: + ```javascript + cloneUser('source.username', 'new.username'); + ``` +4. Click "Run script" + +## What It Does + +The script: +1. Creates a new user record with the specified username +2. Copies all field values from the source user to the new user (except fields already set) +3. Clones all directly assigned roles (excludes inherited roles) +4. Clones all group memberships +5. Returns the sys_id of the newly created user + +## Use Cases + +- Onboarding new team members with similar access needs +- Creating test users with specific role/group combinations +- Setting up backup user accounts with identical permissions +- Standardizing user setup based on role templates diff --git a/Specialized Areas/Fix scripts/Bulk Update User Time Zones/variant.js b/Specialized Areas/Fix scripts/Bulk Update User Time Zones/variant.js new file mode 100644 index 0000000000..df1b585af0 --- /dev/null +++ b/Specialized Areas/Fix scripts/Bulk Update User Time Zones/variant.js @@ -0,0 +1,26 @@ +// Variant: Update users by group name instead of sys_id + +var GROUP_NAME = 'Service Desk'; +var NEW_TIME_ZONE = 'America/Chicago'; + +var groupGR = new GlideRecord('sys_user_group'); +groupGR.addQuery('name', GROUP_NAME); +groupGR.query(); +if (groupGR.next()) { + var groupId = groupGR.sys_id.toString(); + var grMember = new GlideRecord('sys_user_grmember'); + grMember.addQuery('group', groupId); + grMember.query(); + var count = 0; + while (grMember.next()) { + var user = new GlideRecord('sys_user'); + if (user.get(grMember.user)) { + user.time_zone = NEW_TIME_ZONE; + user.update(); + count++; + } + } + gs.print('Updated time zone for ' + count + ' users in group "' + GROUP_NAME + '"'); +} else { + gs.print('Group not found: ' + GROUP_NAME); +} \ No newline at end of file