- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2018 09:09 PM
I had created some validation in Client Script for my page but now i want to create them in Script Include and call it like a function in my Client Script. And have some troubles here ! Example:
This is my CLient Script for email validate
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// var input = g_form.getValue('email');
// var answer = true;
// var regex = /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/ig;
// if(!input.match(regex)){
// g_form.addErrorMessage('Email is invalid format ! (abc@domain.com)');
// answer = false;
// g_form.clearValue('email');
// setTimeout(function(){
// g_form.clearMessages();
// }, 5000);
// }else{
// return true;
// }
var ga = new GlideAjax('emailValid');
ga.addParam('sysparm_name','isEmail');
ga.addParam('sysparam_id',newValue);
ga.getXML(Process);
}
function Process(response) {
var answer = true;
var email = g_form.getValue('email');
if (!email.match(isEmail(email))){
g_form.addErrorMessage('Email is invalid format ! (abc@domain.com)');
answer = false;
g_form.clearValue('email');
setTimeout(function(){
g_form.clearMessages();
}, 5000);
}
}
And here is what i just did with Script include
var emailValid = Class.create();
emailValid.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
isEmail: function(email){
var regex = /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/ig;
return regex.test(email);
},
type: 'emailValid'
});
pls help me solve this !
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2018 05:30 AM
Hi escanor,
Remove the line var answer = true and replace with
var ans = response.responseXML.documentElement.getAttribute('answer');
if(ans == 'false')
{
g_form.clearValue('email');
g_form.clearMessages();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2018 11:58 PM
Happy to hear that enjoy Servicenow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2018 03:05 AM
Hi escanor,
Use following code in your client script,
var ga = new GlideAjax('Script_Include_Name');
ga.addParam('sysparm_name', 'function_name');
ga.addParam('sysparm_newEmail', newValue);
ga.getXML(process);
function process(response)
{
var ans = response.responseXML.documentElement.getAttribute('answer');
if(ans == 'false')
{
alert('Email is not valid.');
}
}
Thanks,
Nitin Tongrao
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2021 10:00 PM
Hi Nitin Tongrao,
Instead of calling the script include from client script. How can i call it from action of flow designer?
