forked from ServiceNowDevProgram/code-snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode.js
More file actions
22 lines (16 loc) · 617 Bytes
/
Code.js
File metadata and controls
22 lines (16 loc) · 617 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
(function executeRule(current, previous /*null when async*/ ) {
// Get Name and User id values
var cleanName = current.name.replace(/,/g, '').trim();
var nameParts = cleanName.split(/\s+/);
var initials = '';
for (var i = 0; i < nameParts.length; i++) {
if (nameParts[i].length > 0) {
initials += nameParts[i][0];
}
}
// Create email alias
var emailAlias = initials.toLowerCase() + '.' + current.user_name.toLowerCase() + '@company.com';
// Set output value to email field
current.email = emailAlias;
current.update();
})(current, previous);