Restrict the use of particular mail id in a field

suuriyas
Tera Contributor

HI Community,

 

I have a requirement, in incident form we have a field called additional assignee list which is list type and reference to user table.

In this field i want to restrict the use of particular mail id let say xx@gmail.com users should not able to enter this particular mail id in that field 

How can we achieve this?

suuriyas_0-1750312413028.png

Note: we don't have any users profile with this mail id but we can able to enter it using highlighted box (add email address)

 

Thanks in Advance

9 REPLIES 9

Community Alums
Not applicable

Please use additional assignee field instead of watchlist, I used it on watchlist field.

Ankur Bawiskar
Tera Patron
Tera Patron

@suuriyas 

you can use onChange client script and see if that email is present, if yes then show error message to that field.

something like this

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    g_form.hideFieldMsg('fieldName');
    if (newValue.indexOf('xx@gmail.com') > -1) {
        g_form.showFieldMsg('field', 'The email address is not allowed', 'error');
    }
    //Type appropriate comment here, and begin script below

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@suuriyas 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@suuriyas 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Chaitanya ILCR
Kilo Patron

Hi @suuriyas ,

use this script 

you can extend this with list of emails added to the array

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var restrictedEmails = ['xx@gmail.com']; //extend this array if required with lower case emils
    restrictedEmails = restrictedEmails.map(function(em) {
        return em.trim().toLowerCase();
    })
    var addRestrictedEmails = [];
    newValue.split(',').forEach(function(i) {

        if (restrictedEmails.includes(i.trim().toLowerCase())) {
            addRestrictedEmails.push(i);
            g_form.setValue('additional_assignee_list', newValue.replace(i, ''));

        }
    });
    if (addRestrictedEmails.length)
        g_form.showFieldMsg('additional_assignee_list', addRestrictedEmails.join() + ' should not be added', 'error');

}

ChaitanyaILCR_0-1750321259690.png

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya