- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-25-2022 04:51 AM
Hi Experts,
Requirement is email validation .That should any email addresses noted in the "Email addresses" field when scheduling a report to be sent must end in company.com or servicenow.com.
"Email address" field is not a catalog variable. It is a field in the "Scheduled report" table.
any number of email address we can give in that field with separating by comma, all email addresses should get validate . and it is not only for any particular report to schedule. It should be for all.
Help me on achieving this.
Thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-25-2022 10:03 AM
Hey
It is fixed now. I tested it in my PDI
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
try {
var emailsArray = [];
var invalidEmails = []
var validEmails = [];
emailsArray = newValue.toString().split(',');
for (var i = 0; i < emailsArray.length; i++) {
if ((emailsArray[i].toString().endsWith("@company.com")) || (emailsArray[i].toString().endsWith("@servicenow.com")))
{
validEmails.push(emailsArray[i]);
} else
{
invalidEmails.push(emailsArray[i]);
}
}
var validEmailsString = validEmails.join(',');
var invalidEmailsString = invalidEmails.join(',');
g_form.setValue('address_list', validEmailsString);
g_form.addErrorMessage("Invalid Emails Removed : " + invalidEmailsString);
} catch (e) {}
}
Previously it didn't work due to recursive call and now its fixed with above script via try catch block.
Mark as correct and helpful if it solved your query.
Regards,
Sumanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-25-2022 05:05 AM
Hi,
you can use normal onChange client script and split the values with comma and then for each value you can check if it's following the standard or not
what's the challenge?
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-25-2022 05:40 AM
Hi
I'm not getting how to validate both mail addresses. Email address must end with either company.com or servicenow.com
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-25-2022 05:44 AM
Hi,
example below
it would show you list of invalid email addresses as well
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
var inValidArr = [];
var isValid = true;
var arr = newValue.split(',');
for(var i in arr){
if(arr[i].toString().endsWith('company.com') || arr[i].toString().endsWith('servicenow.com'))
isValid = true;
else{
isValid = false;
inValidArr.push(arr[i].toString());
}
}
if(isValid.toString() == 'false' && inValidArr.length > 0){
alert("Invalid email addresses " + inValidArr.toString());
}
}
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-25-2022 06:59 AM
Hi,
update as this to show error message near field
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
g_form.hideFieldMsg('fieldName');
var inValidArr = [];
var isValid = true;
var arr = newValue.split(',');
for(var i in arr){
if(arr[i].toString().endsWith('company.com') || arr[i].toString().endsWith('servicenow.com'))
isValid = true;
else{
isValid = false;
inValidArr.push(arr[i].toString());
}
}
if(isValid.toString() == 'false' && inValidArr.length > 0){
g_form.showFieldMsg("fieldName","Invalid email addresses " + inValidArr.toString(),'error', true);
}
}
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader