Send Password to the user straight away using Email notification, when the user is created in SN

Lakshmi Prasann
Giga Expert

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!!!

1 ACCEPTED SOLUTION

AnveshKumar M
Tera Sage
Tera Sage

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.
}

 

 

Thanks,
Anvesh

View solution in original post

4 REPLIES 4

Rahul Kumar17
Tera Guru

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

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar

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

AnveshKumar M
Tera Sage
Tera Sage

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.
}

 

 

Thanks,
Anvesh

sushantmalsure
Mega Sage
Mega Sage

@Lakshmi Prasann 

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 🙂

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,Sushant Malsure