diff --git a/Server-Side Components/Business Rules/Auto Generate Unique Emails for New Users/README.md b/Server-Side Components/Business Rules/Auto Generate Unique Emails for New Users/README.md new file mode 100644 index 0000000000..f182326cb0 --- /dev/null +++ b/Server-Side Components/Business Rules/Auto Generate Unique Emails for New Users/README.md @@ -0,0 +1,4 @@ +Whenever new users onboarded BR will automatically create unique mail to the user and update it to user record. + +Inputs: User Full Name, Unique User ID (Vishnu Kumar, 10321717) +Output: Unique email id generated and tagged to user record. (vk.10321717@company.com) diff --git a/Server-Side Components/Business Rules/Auto Generate Unique Emails for New Users/code.js b/Server-Side Components/Business Rules/Auto Generate Unique Emails for New Users/code.js new file mode 100644 index 0000000000..4ae6f2bdd5 --- /dev/null +++ b/Server-Side Components/Business Rules/Auto Generate Unique Emails for New Users/code.js @@ -0,0 +1,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].toUpperCase(); + } + } + + // 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);