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

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Saurabh,



Based on your req you can achieve this req either with client script or business rule.



Client script approach : You can have a OnChange client script which will pass the current email from the form and then do the validation at the server(GlideAjax) and return the value back to the client.


Business rule approach : You can GlideRecord the sys_user table and pass the current email value and then do the validation.



Please let me know if you have any questions.


hi Pradeep,


can you please post the sample client script for that   using glideAjax since I am new to servicenow I am not getting it. It will be really helpful for me if you can do that


.thank you


http://wiki.servicenow.com/index.php?title=GlideAjax#gsc.tab=0


Please refer the above link..Meanwhile I will help you with the code.


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.