validation for user registration?

Saurabh Kolte
Kilo Contributor

I have a user registration form in that I mentioned email id as my mandatory field. say I am entering the user details with email

Id.

so for that I wanted to use a client script or glideAjax which will be used for restricting of entering the same email id again.

so what script I use for that??? does bussiness rule will be helpful in this case?

1 ACCEPTED SOLUTION

Hi Saurabh,



As promised, here is the code.


Client Script : I've done validation on submit. However you change as per your req.


function onSubmit() {


  //Type appropriate comment here, and begin script below


  var userEmail = g_form.getValue('u_email');


  var ga = new GlideAjax('HelloWorld');


  ga.addParam('sysparm_name','helloWorld');


  ga.addParam('sysparm_user_name', userEmail);


  ga.getXML(HelloWorldParse);



  function HelloWorldParse(response) {


  var answer = response.responseXML.documentElement.getAttribute("answer");


  alert(answer);


  if(answer == 'true')


  {


  alert('Email already exists');


  }


  }


}



Now create a script include:


Name : HelloWorld


Client Callable : True


Script :


var HelloWorld = Class.create();


HelloWorld.prototype = Object.extendsObject(AbstractAjaxProcessor, {


  helloWorld: function() {


  var answer = 'false';


  var usrEmail = this.getParameter('sysparm_user_name');


  var gr = new GlideRecord('sys_user');


  gr.addQuery('email',usrEmail);


  gr.query();


  while(gr.next())


  {


  answer = 'true';


  }


  return answer;


  },



  _privateFunction: function() { // this function is not client callable



}




});



Also I've developed this on below demo instance.


https://demo007.service-now.com/login.do


Username : admin


Password : admin


Steps for testing : go to Incident form there I've created an email field. Onsubmit of the form it will validate and give an alert.



Please change the naming conventions and modify the script as per your req.



If this answers your question, please mark it correct and close the thread.


View solution in original post

11 REPLIES 11

Hi Pradeep,

I am trying to this same thing on a public portal widget.  Could you help me with this please?

Hi, 

Instead of writing a client script or business rule. There is a field in Dictionary Entry as UNIQUE. if you tick that. The field will not accept duplicate entries.