We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Brian Rivera
ServiceNow Employee

Posting this simple solution here. Seen a lot of requests for the OTP Email to be sent out automatically when users are logging in to ServiceNow

 

UI Script - AutoEmailOTP

addLateLoadEvent(function(){
	setTimeout(function(){
		var windowLoc = top.window.location;
		console.log('validating window..,');
		if(windowLoc.href.includes("validate_multifactor_auth_code")){
			console.log('window validated, triggering onClick...');
			multifactorSendOneTimePassword();
		}
	}, 1000); //1 second delay
});

 

Notes:

- Feel free to remove the console.log() lines

- The 1 second delay is necessary to allow window.location.href to change from "navpage.do" to "validate_multifactor_auth_code.do". This may need to increase if some users have particularly slow browsers/PCs.

Version history
Last update:
‎10-26-2022 11:54 AM
Updated by: