Skip to content

Commit ccce4f1

Browse files
authored
Create CloneUser.js
This script is designed to duplicate an existing user record in ServiceNow using the GlideRecord API. It is useful for scenarios where you need to replicate user profiles for testing, onboarding templates, or automation purposes.
1 parent de3ed58 commit ccce4f1

File tree

1 file changed

+22
-0
lines changed
  • Server-Side Components/Background Scripts/Clone User Record

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
var sourceUser = new GlideRecord('sys_user');
2+
3+
// Replace 'user_name' with the actual username or use sys_id
4+
if (sourceUser.get('user_name', 'john.doe')) {
5+
var clonedUser = new GlideRecord('sys_user');
6+
clonedUser.initialize();
7+
8+
// Copy fields from source user
9+
clonedUser.name = sourceUser.name + ' (Clone)';
10+
clonedUser.email = sourceUser.email;
11+
clonedUser.department = sourceUser.department;
12+
clonedUser.title = sourceUser.title;
13+
clonedUser.phone = sourceUser.phone;
14+
clonedUser.location = sourceUser.location;
15+
clonedUser.manager = sourceUser.manager;
16+
17+
// Insert the cloned user record
18+
var newUserID = clonedUser.insert();
19+
gs.info('Cloned user created with sys_id: ' + newUserID);
20+
} else {
21+
gs.info('Source user not found');
22+
}

0 commit comments

Comments
 (0)