Email validation on Multi-row variable sets
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2023 04:37 AM
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?
I need help to build a solution for the above requirement.
TIA,
DB
@Peter Bodelier @Ankur Bawiskar @AnveshKumar M
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2023 10:40 AM
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;
}
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2023 09:08 PM
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();
},
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2023 11:47 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2023 12:15 AM - edited 10-12-2023 12:15 AM
Hello @DB1,
Make sure you selected Client Callable checkbox while creating Script Include.
Thanks
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2023 12:19 AM
is the script include getting called?
please share your script include code and also the screenshot.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader