- 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:09 AM
Hi CHAITHNYA,
you can use following code in onChange client script,
var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/; // regex pattern
if (!pattern.test(newValue))
and provide you logic for multiple email using comma separation.
If it helps you to achieve your requirement please mark helpful.
Thank you
Gaurav Rotke

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-25-2022 05:16 AM
Hi Chaithanya,
You can write an onChange Client script on email addresses field as below
var emailsArray = [];
emailsArray = newValue.toString().split(',');
for(var i=0; i<emailsArray.length;i++)
{
if(!emailsArray[i].toString().endsWith("@company.com"))
{
//g_form.addInfoMessage(emailsArray[i] +" is not in proper format");
emailsArray.splice(i);
}
}
This will remove all the email address from the field which do not end with company.com
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:28 AM
Hi
Thanks for the reply.
And the given coding is working . and it is taking only company.com address. but the requirement is field should take "servicenow.com" mail address as well. email address must end in company.com or servicenow.com.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-25-2022 05:45 AM
You can try adding another condition in if loop. I left it so that you will try.
Here is the updated script :
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")) )
{
//g_form.addInfoMessage(emailsArray[i] +" is not in proper format");
emailsArray.splice(i);
}
}
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:52 AM
You can try this as well if you want to show the invalid email addresses which are removed.
var invalidemails;
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")) )
{
invalidemails += emailsArray[i] + ", ";
emailsArray.splice(i);
}
}
var message = invalidemails.slice(0,-1);
gs.addErrorMessage("Removed Invalid emails : "+message);