How ServiceNow sends email with Password and URL to Newly Created users?

Sailesh4
Giga Expert

Hi All,

 

We have a requirement where when a new user is created manually in ServiceNow, a email needs to be triggered with the password(Which ServiceNow automatically sets) along with the link to change the password. Also I want ServiceNow to set passwords automatically to the newly created users.

 

Is there any way we can get this done?

 

Regards,

Sailesh J

1 ACCEPTED SOLUTION

Hi Mohit,

 

Thank you for your time.

 

I have completed the requirement. I have written a after - Insert Business Rule for getting this functionality.

 

(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);

//gs.eventQueue()
}

gs.eventQueue("user.password", current, randomstring, current.email);

current.user_password.setDisplayValue(randomstring);
current.password_needs_reset = true;
// gs.log("randomstring: " + randomstring, 'c1006');
// gs.log("password: " + current.user_password, 'c1006');

current.update();
})(current, previous);

 

Hope this helps for anyone 🙂

 

Regards,

Sailesh J

View solution in original post

13 REPLIES 13

Thank you Mohit.

Our client needs the password to be autopopulated and user needs to login to that password which got generated. Please provide the code once done.

Hi Mohit,

 

Have you got the fix by any chance?

 

Regards,

Sailesh J

Hi Sailesh,

I tried for it but everything is reaching to dead end, i am afraid you need to remove the password value from email script and mention the line to reset the password.

Instead of making the user change its password again after first login, you can uncheck the "Password reset" checkbox and make your notification run on some custom field value change, in that way they have to change the pwd once.

 

Thanks,

Mohit Kaushik 

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)

Hi Mohit,

 

Thank you for your time.

 

I have completed the requirement. I have written a after - Insert Business Rule for getting this functionality.

 

(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);

//gs.eventQueue()
}

gs.eventQueue("user.password", current, randomstring, current.email);

current.user_password.setDisplayValue(randomstring);
current.password_needs_reset = true;
// gs.log("randomstring: " + randomstring, 'c1006');
// gs.log("password: " + current.user_password, 'c1006');

current.update();
})(current, previous);

 

Hope this helps for anyone 🙂

 

Regards,

Sailesh J