Inbound action with if statement checking email.direct fails when the address is also in the CC field

Tony V
Tera Guru

I have an inbound action that checks for an email address using email.direct but the if statement i the script appears to evaluate as false when the address is in also in the CC field. 

So the purpose of the if statement in the script is that if one of two email addresses are in the TO field then set certain properties. When one of those address is ONLY on the TO field is works as expected. When that address is in both the TO and CC fields it fails.

Here is the snippet

if  (email.direct.toLowerCase().indexOf('111@111.com') != -1 || email.direct.toLowerCase().indexOf('222.222.com') != -1) {
	current.urgency = 2;
	current.assignment_group.setDisplayValue("Customer");
	
}

The situation happens with the second address only. Since this change was implemented the customer has not had any emails received that include the first address so I don't know if the same would happen with that one.

I have confirmed that in each case this is the only inbound action that processed the email, there are no other rules or scripts modifying the Assignment group after the fact, The rest of the script is very simple and has no other if statements.

(I know using setDisplayValue is not best practice and that will be addressed later. For now that is not related to this issue.)

Thoughts?

1 ACCEPTED SOLUTION

Tony V
Tera Guru

The answer was to modify the code to use email.to which evaluates both the TO and CC fields instead of email.direct which evaluates just the TO field. Here is why:

In the end the confusion was caused by the email being presented in the activity stream incorrectly. It showed all the addresses in the CC field duplicated in the TO field. So it appeared that the sender was adding the address to both the TO and CC fields. In fact the address was just in the CC field and ServiceNow for some reason shows it in both. If I went to the log of the incoming email and looked at the email header it clearly showed that the address in question was ONLY in the CC field.

So what I thought was a bug was actually expected behavior. It was just that the SN interface was showing me inaccurate information and it made troubleshooting very difficult.

Just to be clear: if an email was sent TO: 111@111.com and CC: 222@222.com, the incident activity stream would show:

TO: 111@111.com; 222@222.com
CC: 222@222.com

I did contact HI and in the end the technician raised an issue with their DEV team. We will see if that gets fixed.

View solution in original post

3 REPLIES 3

Community Alums
Not applicable

Hi Tony,

 

We are also facing same kind issue  after kingston upgrade ..

Is it resolved at ur end.

 

Regards,

Roopa

Tony V
Tera Guru

The answer was to modify the code to use email.to which evaluates both the TO and CC fields instead of email.direct which evaluates just the TO field. Here is why:

In the end the confusion was caused by the email being presented in the activity stream incorrectly. It showed all the addresses in the CC field duplicated in the TO field. So it appeared that the sender was adding the address to both the TO and CC fields. In fact the address was just in the CC field and ServiceNow for some reason shows it in both. If I went to the log of the incoming email and looked at the email header it clearly showed that the address in question was ONLY in the CC field.

So what I thought was a bug was actually expected behavior. It was just that the SN interface was showing me inaccurate information and it made troubleshooting very difficult.

Just to be clear: if an email was sent TO: 111@111.com and CC: 222@222.com, the incident activity stream would show:

TO: 111@111.com; 222@222.com
CC: 222@222.com

I did contact HI and in the end the technician raised an issue with their DEV team. We will see if that gets fixed.

Prerana1
Kilo Guru

Hello Tony,

Did you get the solution for that, i am also facing the same issue.

 

Thanks,

Prerana