- 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 06:12 AM
Hi
for this condition, it is not taking company or servicenow address.
after alert it is clearing the field.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var emailsArray = [];
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")) )
{
alert('invalid');
g_form.clearValue('address_list');
emailsArray.splice(i);
}
}
}
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-25-2022 06:22 AM
Did you get a chance to check my above script?
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:31 AM
Hi
Yes I have tried that one as well, the same thing is happening.
And If I give any address like gmail.com or yahoo.com also after clicking ok on alert message. It is allowing to save the form. If I give company.com also happening the same thing
Irrespective of the addresses it is showing alert message after that it is allowing to save the form.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-25-2022 07:00 AM
you can use error to show near the field as field message
So in this way user cannot submit form
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:40 AM
Your final code should look like below.
Now it will remove the invalid emails from the list aswell.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var emailsArray = [];
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")) )
{
emailsArray.splice(i);
}
}
var updatedEmails = emailsArray.join(',');
g_form.setValue('address_list', updatedEmails);
}