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

No it does not create the email address for the user, its just add the email of that user to cc, but you can ignore that line. That is not required as you are directly setting the recipient email for notification.

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)

Hi Mohit,

 

Forgot to mention.

 

ServiceNow is not allowing the newly created user to login using the default password which we used in email script. Do you know why this is happening?

 

Regards,

Sailesh J

Let me look into this,

Can you please share the screenshot, which is not allowing the user to login.

 

Thanks,

Mohit Kaushik

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)

PF screenshot.

find_real_file.png

I have created a new user to test the functionality. The notification is going correctly, but while logging using the given password it is saying that your password is wrong.

HI Sailesh,

Sorry for the trouble with the code, but i was checking that the password which comes through glide property that is some default password which needs to be reset on first login.

find_real_file.png

For resetting the pwd the user needs to click on forgot password button.

here is the link which you can provide to the user for logging in.

https://docs.servicenow.com/bundle/newyork-platform-administration/page/administer/security/concept/...

 

Now i will suggest you instead of passing the pwd in mail you can just mention their mail id and write a line that they need to click on the forgot pwd button to reset and they can follow the above link also to follow the steps.

Now after this one more challenge will come that when you will reset the pwd and log into snow instance after this it will again ask you to change the pwd as we have checked the password reset checkbox.

Note: Instead of all this we can write one script to auto populate the pwd and i am working on that once that is done i will share the solution with you.

Then you will not require the email script, it will be done with the help of client script only, i think.

 

 

Thanks,

Mohit Kaushik

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)