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-09-2023 05:29 AM
Hi @DB1 ,
Create on change client script on Email variable and add below code:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2023 05:33 AM
Hi @DB1
You can write script include & onChange Catalog client script written on MRVS
Client callable Script include :
Name : userUtils
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();
if (grUser.next()) {
isEmailPresent = "true";
} else {
isEmailPresent = "false";
}
return isEmailPresent;
},
Client script :
function onChange(control, oldValue, newValue, isLoading) {
if(isLoading){
return;
}
var email = g_form.getValue('email');
var ga = new GlideAjax('userUtils'); // scripot include name
ga.addParam('sysparm_name', 'checkUserEmail'); // function name
ga.addParam('sysparm_email', email);
ga.getXMLAnswer(callBackFun);
function callBackFun(answer) {
if(answer == 'true'){
g_form.showErrorBox('email', "Email id already present");
}else {
g_form.showFieldMsg('email', "You can proceed with this email");
}
}
}
Make sure that Client script written on your MRVS :
Output :
Email already exist :
New email :
Additional information :
You can set "g_scratchpad" value depending upon result in client script & use that g_scratchpad value in onSubmit script to allow (if new email) or abort the submission if (email already exist)
Hope this helps...!!
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-09-2023 06:46 AM
What did you start with? It should be an easy task
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 10:07 AM
Hi All, Thanks for your replies. I was not available until today.
@Ankur Bawiskar @Vishal Birajdar
I have the script include and client script as below
SI:
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();
if (grUser.next()) {
isEmailPresent = "true";
} else {
isEmailPresent = "false";
}
return isEmailPresent;
},
client:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var email = g_form.getValue('abc_external_email');
var ga = new GlideAjax('ABC_checkUserEmail'); // script include name
ga.addParam('sysparm_name', 'checkUserEmail'); // function name
ga.addParam('sysparm_email', email);
ga.getXMLAnswer(callBackFun);
function callBackFun(answer) {
if(answer == "true"){
//g_form.showErrorBox('crf_external_email', "Email id already present");
return true;
}
else
{
g_form.showErrorBox(email, "Email Id does not exist");
return false;
}
}
}
I have applied it to the variable set only. still I do not see any error message.
I want the error message only when email id is not found on sys_user table. If found it should not do anything just return true