We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

User Creation Email with Password Reset Link

rah dev
Tera Contributor

 

Hi community, good day.

I have a requirement: there is a notification set up on the User table. I want that whenever a user is created, the notification should be triggered for that particular user. In that notification, there should be an email script for resetting the password. When the user clicks on it, they should be redirected to the password reset screen where they can set their password.

I am currently using this script on a normal page, but the result is that it redirects me to the login screen instead.

(function runMailScript(current, template, email, email_action, event) {

    var baseUrl = gs.getProperty('glide.servlet.uri');

    if (!current || current.getTableName() != 'sys_user') {
        template.print("Invalid user record.");
        return;
    }

    var resetLink = baseUrl + "login.do?sysparm_url=/$pwd_reset.do?sysparm_user=" + current.user_name;

    template.print("<p>Dear " + current.name + ",</p>");
    template.print("<p>You have successfully registered.</p>");
    template.print("<p>Please click the link below to set your password:</p>");
    template.print("<p><a href='" + resetLink + "'>Set Your Password</a></p>");
    template.print("<p>If you did not request this, please ignore this email.</p>");

})(current, template, email, email_action, event);

rahdev_1-1771002957452.png

 

10 REPLIES 10

@rah dev 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar tried with same code but it is taking to the below page and that's showing the error page. How can we configure it.

rahdev_0-1771314148869.png

 

@rah dev 

image is too small

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

rahdev_0-1771315190050.png

 

@rah dev 

Usually users are onboarded on sys_user either via LDAP/AD OR Azure

With this the password is not stored in instance but users are authenticated via that mechanism

then why this requirement?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader