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

Mohit Kaushik
Mega Sage
Mega Sage

Hi Sailesh,

You can write email notification for a new user creation. For this you can create a custom field in user table which will be marked true when you are creating a user manually. To check if it is manual creation for that set the custom field true with the help of client script.

Once that field is marked true you can trigger the notification to user for his id creation.

Now for changing the password link, you can just select the check box for change password in user table and whenever the user will login first time it will ask the user to change the password.

Now to auto populate the password you can write some script, which you can easily get on google.

 

Please mark this answer correct if it resolved the query and mark it helpful if it helped you at all.

 

Thanks,

Mohit Kaushik

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)

Hi Mohit,

 

Thanks for your input.

 

I want any scripts or any links to the documents where I can find some help in getting this requirement done. Please provide if any.

 

Regards,

Sailesh J

Mohit Kaushik
Mega Sage
Mega Sage

Hi Sailesh,

You can refer the below link to create notification into Servicenow. And instead of creating a custom field to capture manual creation you can just mark the "Password need reset" field to checked. 

https://docs.servicenow.com/bundle/newyork-servicenow-platform/page/administer/notification/task/t_C...

And you can use the same in triggering condition also of your notification email.

For showing the credentials into notification you can create an email script and call it inside the notification message box.

Please find the attached screenshot for the email script and notification.

 

 

Please mark this answer correct if it resolved the query and mark it helpful if it helped you at all

Thanks,

Mohit Kaushik

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)

Hi Mohit,

 

Thank you for the attachments.

 

In the email script, what does the last line do? Does it create an email address for the user that has been created?

 

regards,

Sailesh J