Need to highlight HR cases created from certain emails via inbound action

Arka Banerjee
Kilo Guru

Hi All,

 

ArkaBanerjee_0-1745250194321.png

 

Above is a screenshot of a HR case created from an Inbound email action.

 

I need to display an error message at the top, above the info message that you see in the screenshot, whenever the sender's email domain(i.e. the person who sent the email via which the case got created in SNOW) isn't among the whitelisted ones(@abc.com ,  @xyz.com for egs), mentioning something like 'This email isn't from a trusted domain. Kindly proceed with caution.'

 

Can someone please help me achieve this. Thanks!

 

@Ankur Bawiskar 

1 ACCEPTED SOLUTION

Hi Ankur,

 

I have created a custom field for the form, populated the sender email from the inbound action by setting the field's current value with email.origemail, and then used your script, it worked as expected.

View solution in original post

10 REPLIES 10

Ankur Bawiskar
Tera Patron
Tera Patron

@Arka Banerjee 

it's an easy onload client script to add color and show message

something like this if the field is editable

function onLoad() {

    // Allowed domains
    var allowedDomains = ['@abc.com', '@xyz.com'];

    // Get the email origination field value
    var emailOrigination = g_form.getValue('email_originationField');

    if (emailOrigination) {
        // Extract the domain from the email
        var emailDomain = emailOrigination.substring(emailOrigination.indexOf('@'));

        // Check if the domain is not in the allowed domains list
        if (!allowedDomains.includes(emailDomain)) {
            // Highlight the field in orange
            var control = g_form.getControl('email_originationField');
            control.style.backgroundColor = "orange"; // to set the background color

            // Display an error message
            g_form.addErrorMessage("This email isn't from a trusted domain. Kindly proceed with caution.");
        }
    }

}

Something like this if field is readonly

function onLoad() {

    // Allowed domains
    var allowedDomains = ['@abc.com', '@xyz.com'];

    // Get the email origination field value
    var emailOrigination = g_form.getValue('email_originationField');

    if (emailOrigination) {
        // Extract the domain from the email
        var emailDomain = emailOrigination.substring(emailOrigination.indexOf('@'));

        // Check if the domain is not in the allowed domains list
        if (!allowedDomains.includes(emailDomain)) {
            // Highlight the field in orange

            var table = g_form.getTableName();
            var fieldName = 'email_originationField';

            var ctrl = g_form.getControl(table + '.' + fieldName);
            if (ctrl['nodeName'] != 'SELECT') {
                ctrl = g_form.getControl('sys_readonly.' + table + '.' + fieldName);
                ctrl.style.backgroundColor = 'orange';
            }

            // Display an error message
            g_form.addErrorMessage("This email isn't from a trusted domain. Kindly proceed with caution.");
        }
    }

}

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

@Arka Banerjee 

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

@Arka Banerjee 

Thank you for marking my response as helpful.

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

Thanks Ankur. 

 

However, I just got to know that the ' Email Origination' field isnt really the sender's email address, but actually the recipient email address. So, I don't quite have the sender's email address in the form. 

 

I have updated my requirement in the question, where I would just need to print that error message, but now since I dont have the senders email address in the form, can you please help me achieve this. Thanks!