Validation for MVRS variable set

Gowtham29
Tera Expert

Hi Team,

We have a MVRS variable set on the catalog item form to add users in to the sys_user table, with variables as First Name, Last Name, Email. Now I need to check if the user present in user table using email variable from MVRS, if the user exists in the table then I need to show an alert saying that user already exists, if not allow user to submit the request.

Gowtham29_0-1693324239907.png

 

1 REPLY 1

Mohith Devatte
Tera Sage
Tera Sage

Hello @Gowtham29 ,

You can write an on change client script inside MVRS which will call a script include to check in user table that if any user has the same email id .

 

Client script :

 

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

	var user = g_form.getValue('your_email_id_variable_backend_name');

	//Call script include
	var ga = new GlideAjax('checkUserDetails');   //Scriptinclude
	ga.addParam('sysparm_name', 'getUserDetails'); //Method
	ga.addParam('userId',user); //Parameters
	ga.getXMLAnswer(getResponse);
	
	function getResponse(response){
		if(response==true||response=="true")
{
alert("User Already exists in database");
g_form.clearValue('your_email_field_backend_name');
return false;
}
		
	}
	
}

 

Script include :Make sure your scirpt include name is checkUserDetails

 

var checkUserDetails = Class.create();
checkUserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	getUserDetails: function(){
		
		
		var userId = this.getParameter('userId');
			

	var grSysUser = new GlideRecord('sys_user');
         grSysUser.addQuery('email',userId);
         grSysUser.query();
	if (grSysUser.next()) {
	 return true;
	}
else
{
return false;
}
	
	},

	type: 'checkUserDetails'
});

 

 

Hope this helps 

Mark the answer correct if this helps you 

Thanks