Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Brian Rivera
ServiceNow Employee
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: