Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Inbound Email Action condition script is not working

siva44
Tera Contributor

Hi to All,

I have created one inbound email action  with specific condition for creation of incident and condition script like below

 

"!(email.origemail == 'Alerts@group.com') && subject.toLowerCase().indexOf(" fw: card library") == -1"

 

But whenever i am forwared one email to servicenow with subject like fw: card library then also the inbound action triggering and created the incident.

please let me known if anyone known 

4 REPLIES 4

Rajesh Chopade1
Mega Sage

Hi @siva44

Following are possible issues:

The subject may have varying spaces or characters (e.g., extra spaces after "FW:" or variations like "Fwd:").

The indexOf method returns -1 if the string isn't found, but your check might miss subtle variations.

 

I will suggest use ‘Normalize the subject’  & use ‘Regular expressions’ to match variations  of ‘FW: card library’

 

// Normalize email subject by trimming spaces and converting to lowercase
var subjectNormalized = subject.toLowerCase().trim();

// Regular expression to match variations of "FW: card library"
var regex = /fw:\s*card library/i;

if (email.origemail != 'Alerts@group.com' && !regex.test(subjectNormalized)) {
    // Your action logic here (creation of incident, etc.)
    gs.log("Email condition met, inbound action triggered.");
    // Return true to trigger the inbound email action
    return true;
}

// Return false to stop the action from triggering
gs.log("Email condition not met, no action taken.");
return false;

 

I hope my answer helps you to resolve your issue, if yes please mark answer as correct and helpful.

thank you

rajesh

Hai @Rajesh Chopade1  can u tell me where  your script is use 

Hi @siva44

You should update this script in the Condition Script section of your Inbound Email Action in ServiceNow.

- Go to System Policy > Email > Inbound Actions in the application navigator.

- Search for the specific Inbound Email Action where you want to implement the condition.

- Scroll down to the Actions tab, where you will see a section for Script.

- update the script, click Save or Update to apply the changes.

okay I will try @Rajesh Chopade1