Email validation on Multi-row variable sets

DB1
Tera Contributor

Hi All,

 

I am looking for solution help with the below requirement.

 

1. I have a multi-row variable set with variables : "Name", "Title", "Phone", "Email" etc.

2. I want to have the validation on "Email".

Detail: If the User enters an email address it has to check the "sys_user" database to see if it returns any entry from the User record. If yes, it has to throw an error "User found!"

Can we do the validation on each row of the Multi- row variable when "Add" is selected every time?

 

DB1_0-1696851310887.png

 

 

I need help to build a solution for the above requirement.

 

TIA,

DB

 

@Peter Bodelier @Ankur Bawiskar  @AnveshKumar M 

 

 

 

 

11 REPLIES 11

Hi @DB1 

 

In client script in else part , use your variable name in quotes

 

		else 
	
		{
			g_form.showErrorBox("your_variable_name", "Email Id does not exist"); // variable name to be used in quotes
			return false;
		}

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

@DB1 

Update as this

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}

	var email = g_form.getValue('abc_external_email');

	if(oldValue != newValue){
		var ga = new GlideAjax('ABC_checkUserEmail');  // script include name
		ga.addParam('sysparm_name', 'checkUserEmail');  // function name
		ga.addParam('sysparm_email', email);
		ga.getXMLAnswer(function(answer){
			if(answer == "false"){
				g_form.clearValue('abc_external_email'); // give here user_id variable name
				g_form.showFieldMsg('abc_external_email',"Email Id does not exist",'error', true);
			}
		});
	}
}

Script Include:

checkUserEmail: function() {

	var isEmailPresent;
	/* Get email from MRVS email field */
	var email = this.getParameter('sysparm_email');

	/*  glide record on user table and check email address - hoping you are checking it on user table*/
	var grUser = new GlideRecord('sys_user');
	grUser.addQuery('email', email);
	grUser.query();
	return grUser.hasNext().toString();
},
Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

For some reason the answer is returning "null" when I tried to alert the answer

 

SI:

checkUserEmail: function() {
		var emailaddress = this.getParameter('sysparm_email');
		var gr = new GlideRecord("sys_user"); 
		gr.addQuery("email", emailaddress);
		gr.query();
		if (gr.next()) {
			return  true;
		}else{
			return  false;
		}
	},

Client script:

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}
	var email = g_form.getValue('abc_external_email');
	alert(email);
	var ga = new GlideAjax('ABC_checkUserEmail');  // script include name
	ga.addParam('sysparm_name', 'checkUserEmail');  // function name
	ga.addParam('sysparm_email', email);

	ga.getXML(gaResponse);
	function gaResponse(response) {
		var answer = response.responseXML.documentElement.getAttribute('answer');
		alert(answer);
		if (answer == false) {
			g_form.showFieldMsg('abc_external_email',"Email Id does not exist",'error', true);
		}
	}

}

alert(answer) - returns null value

Community Alums
Not applicable

Hello @DB1,

 

Make sure you selected Client Callable checkbox while creating Script Include.

 

Thanks

Anand

@DB1 

is the script include getting called?

please share your script include code and also the screenshot.

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