Validation for the "email address" field in "scheduled email report" table

Community Alums
Not applicable

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.

find_real_file.png


Help me on achieving this.

 

Thanks in advance!

1 ACCEPTED SOLUTION

Hey @CHAITHANYA ,

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

View solution in original post

16 REPLIES 16

Community Alums
Not applicable

Hi @SUMANTH DOSAPATI 

The above code is not working .It is taking all the email address.find_real_file.png.

Hey @CHAITHANYA ,

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