- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2021 04:43 AM
Hi,
When a new user is created automatic user name should populate in the user name field using the first two letters of the first name and last name and some random number between 0 to 1.
Thanks in Advance.
Regards,
Chaitanya
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2021 05:11 AM
Hello Chaitanya,
Write a Business rule on sys_user table with the condition below
and here is the code
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var fname=current.first_name;
var lname=current.last_name;
var x = Math.floor((Math.random() * 2) + 1); //Generates random number from 1-2
var username=fname+'.'+lname+x;
current.user_name=username;
current.update();
gs.log(username);
})(current, previous);
I hope this helps!
Mark answer Correct and helpful if this solves your issue.
Thanks,
Hemant
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2021 05:10 AM
Hi Chaitanya,
Try to use the BR function and concatenate the User name with random number . You can use the random function to generate the random number :
https://www.w3schools.com/js/js_random.asp
Let me know if this helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2021 05:42 AM
Hi Niharika,
I am able to create number by every time while saving it. it is getting updated with a new number every time
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2021 05:11 AM
Hello Chaitanya,
Write a Business rule on sys_user table with the condition below
and here is the code
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var fname=current.first_name;
var lname=current.last_name;
var x = Math.floor((Math.random() * 2) + 1); //Generates random number from 1-2
var username=fname+'.'+lname+x;
current.user_name=username;
current.update();
gs.log(username);
})(current, previous);
I hope this helps!
Mark answer Correct and helpful if this solves your issue.
Thanks,
Hemant
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2021 05:40 AM
Hi Hemant,
By using this script and condition I am not able to create it.