- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on ‎10-16-2020 10:30 AM
Hi All,
Recently, I have created a functionality where you can generate automated passwords and send notifications to the manually created new users in ServiceNow.
Please find below the Business Rule details:
Table: User(sys_user)
Before Insert
Conditions:
Created by is not System
(function executeRule(current, previous /*null when async*/ ) {
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var string_length = 8;
var randomstring = '';
for (var i = 0; i < string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum, rnum + 1);
}
//Generate Notification
gs.eventQueue("user.password", current, randomstring, current.email);
//Set values in User record
current.user_password.setDisplayValue(randomstring);
current.password_needs_reset = true;
current.update();
})(current, previous);
You can trigger the Notification and send the user's email and password in the parameters.
Note: You can even reuse the same code for reset the password.
Thanks & Regards,
Sailesh J
- 3,394 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Sailesh,
Good article, Could you please confirm on how can we generate the password such a way like it contains special characters also?
Regards!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Dinesh,
Thanks for marking my article as Helpful.
You can add the required special characters, numbers in the variable "chars" and use the variable "string_length" for the length of the string required.
Just an FYI..
The passwords generated will be completely random. It is not 100% sure that we will get a word from it.
Regards,
Sailesh J
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Sailesh,
Thank you for the knowledge sharing. Keep doing good work like this.
Regards,
Dinesh
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi,
You can use GlideSecureRandomUtil.getSecureRandomString(8) for creating random passwords.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
i am getting the password but in encrypted form how can i decrypt and send it
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I'm newer to SN, where does the code get added. I wanna try this to help speed up generating of onboarding many new users.