- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2023 06:32 AM
Hello Team,
I have configured a email notification and created an event to trigger that notification which runs when a user is created and admin role is assigned to him, a notification should be sent to him which contains username,password and email ID.But there is an issue related to password, as we are setting password using "Set Password" UI action, The password is not reflecting in the email. How can i achieve this ??I want to sent the password generated through Set Password button to the created user.
Need suggestions from you all,
Thanks in Advance!!!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2023 08:06 AM
Hi @Lakshmi Prasann ,
You can use the following script to set the password and use the same variable to send mail.
var userName = 'YOUR_USER_NAME';
var password = SNC.PasswordPolicyEvaluator.generateUserPassword(userName);
var result = SNC.PasswordPolicyEvaluator.setUserPassword(userName, password);
var parsedResult = JSON.parse(result);
var success = parsedResult.success;
if (success){
//Password set successfully and the variable "password" has the secret.
}
Anvesh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2023 07:02 AM
Hi @Lakshmi Prasann ,
f you're using the "Set Password" UI action to generate a password for the user, you can access the generated password in your email notification script by using the "password" field on the GlideRecord object for the User table.
Here's an example email notification script that includes the generated password:
var user = new GlideRecord('sys_user');
user.addQuery('sys_id', event.parm1); // event.parm1 contains the sys_id of the created user
user.query();
if (user.next()) {
var email = user.email.toString();
var username = user.user_name.toString();
var password = user.password.toString(); // Access the generated password here
var message = "Dear " + username + ",\n\n";
message += "Your account has been created with the following credentials:\n\n";
message += "Username: " + username + "\n";
message += "Password: " + password + "\n";
message += "Email ID: " + email + "\n\n";
message += "Please log in to your account at [insert login URL here].\n\n";
message += "Thank you,\nThe IT team";
gs.eventQueue("email.send", user, "New user account created", message, "", "", "", "");
}
Thanks,
Rahul Kumar
Thanks,
Rahul Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2023 07:54 AM - edited ‎04-18-2023 07:55 AM
Hi @Rahul Kumar17 ,
By using this email notification script (Glide Record), we cannot fetch the value of the password, as password is an encrypted value. Please let me know if you have any other solution for this.Thanks for the quick response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2023 08:06 AM
Hi @Lakshmi Prasann ,
You can use the following script to set the password and use the same variable to send mail.
var userName = 'YOUR_USER_NAME';
var password = SNC.PasswordPolicyEvaluator.generateUserPassword(userName);
var result = SNC.PasswordPolicyEvaluator.setUserPassword(userName, password);
var parsedResult = JSON.parse(result);
var success = parsedResult.success;
if (success){
//Password set successfully and the variable "password" has the secret.
}
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2023 08:06 AM
You will have to decrypt the password value before using it in email body.
something like this:
var user = new GlideRecord('sys_user');
user.addQuery('sys_id', event.parm1); // event.parm1 contains the sys_id of the created user
user.query();
if (user.next()) {
var Encrypter = new GlideEncrypter();
var decrypted = Encrypter.decrypt(user.password);
var email = user.email.toString();
var username = user.user_name.toString();
var message = "Dear " + username + ",\n\n";
message += "Your account has been created with the following credentials:\n\n";
message += "Username: " + username + "\n";
message += "Password: " + decrypted + "\n";
message += "Email ID: " + email + "\n\n";
message += "Please log in to your account at [insert login URL here].\n\n";
message += "Thank you,\nThe IT team";
gs.eventQueue("email.send", user, "New user account created", message, "", "", "", "");
}
havent tested the code but should work, you may need t adjust a bit here and there.
Let us know how this goes 🙂
Regards,Sushant Malsure