Self Service Password Reset with Active Directory
///// FROM //////
//alert and exit if ldap account
if (usr.source.toString().startsWith('ldap')) {
msg = gs.getMessage("Use your network password to log into Service-now. If your network password does not work, contact your service desk.");
return "Error:" + msg;
}
///// TO //////
if (usr.source.toString().startsWith('ldap')) {
// msg = gs.getMessage("Use your network password to log into Service-now. If your network password does not work, contact your service desk.");
// return "Error:" + msg;
newpw = "";
var availablechars = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
for(var x = 0; x < 8; x++) {
randomNumber = Math.floor(Math.random() * availablechars.length);
newpw += availablechars[randomNumber];
}
//create the variables for calling the workdlow
var vars = {};
vars.u_username = userid;
vars.u_password = newpw;
//call the AD Password Reset workflow
var w = new Workflow();
var wfid = w.getWorkflowFromName("AD Password Reset");
w.startFlow(wfid, null, 'AD Password Reset', vars);
msg = gs.getMessage("Your password has been reset and will be emailed to the address in our system");
return "Success:" + msg;
}
This is a simple solution to prove out the functionality. This will allow the password reset functionality to work for locally authenticated users and Active Directory users. Tailor the logic, temporary password generation logic and Password Reset Activity parameters as necessary to suit your needs.
https://www.servicenow.com/community/in-other-news/self-service-password-reset-with-active-directory/ba-p/2284124