The CreatorCon Call for Content is officially open! Get started here.

Inbound Action - Recipient Contains

Kiera Mears
Mega Guru

Hello,

 

Today we found an issue with one of our inbound action where it is set to activate if Recipient CONTAINS lis@OurOrganisation.com. This is how all of our inbound actions have always been set up and have worked without issue.  However, today it got triggered because a user who's email address ended in lis@OurOrganisation.com (e.g. John.Salis@OurOrganisation.com) was in the recipients list.

 

Is there a smarter way of configuring this? I can't just put 'Recipient IS lis@OurOrganisation.com' because sometimes it will include multiple individuals in the Recipient field, and the same goes for the 'To' field.

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@Kiera Mears 

you can use script in that inbound action

// Get the recipients from the email
var recipients = email.recipients.split(',');

// Define the specific email address to check
var specificEmail = 'lis@OurOrganisation.com';

// Flag to determine if the specific email is found
var emailFound = false;

// Loop through each recipient and check for an exact match
for (var i = 0; i < recipients.length; i++) {
    var recipient = recipients[i].trim();
    if (recipient.toLowerCase() === specificEmail.toLowerCase()) {
        emailFound = true;
        break;
    }
}

// If the specific email is found, proceed with the inbound action
if (emailFound) {
    // Your inbound action logic here
    gs.info('Specific email found, proceeding with inbound action.');
} else {
    gs.info('Specific email not found, skipping inbound action.');
}

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

There are 2 emails it needs to identify in the 'specificEmail', how do I add an 'or'?

@Kiera Mears 

enhance as this

I believe I have answered your original question.

// Get the recipients from the email
var recipients = email.recipients.split(',');

// Define the specific email address to check
var specificEmail = 'lis@OurOrganisation.com';
var specificEmail1 = 'lis1@OurOrganisation.com';

// Flag to determine if the specific email is found
var emailFound = false;

// Loop through each recipient and check for an exact match
for (var i = 0; i < recipients.length; i++) {
    var recipient = recipients[i].trim();
    if (recipient.toLowerCase() === specificEmail.toLowerCase() || recipient.toLowerCase() === specificEmail1.toLowerCase()) {
        emailFound = true;
        break;
    }
}

// If the specific email is found, proceed with the inbound action
if (emailFound) {
    // Your inbound action logic here
    gs.info('Specific email found, proceeding with inbound action.');
} else {
    gs.info('Specific email not found, skipping inbound action.');
}

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

@Kiera Mears 

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