Email.Body.Variables works for inbound action from certain emails, comes through "undefined" for other emails.

Mike Reed1
Giga Contributor

I am building an inbound action to create a catalog req/req item, and assign variables of the req item with variables from my email. 

The inbound email body always contains an "Email Address" variable. Here is an example: find_real_file.png

The inbound action script contains the following code: 

cart.setVariable(item, 'additional_comments', email.body.email_address.trim());

The final version won't have that line of code, but I am just trying to set the additional_comments variable with the email address for testing purposes.

When the second user sends an email to our ServiceNow instance, the variable comes through as "undefined" on the resulting RITM.

find_real_file.png

If I take the second users email, compose a new email myself, and paste in the exact text from her email into my email, and send it, the variable flows through properly.

 find_real_file.png

It's worth noting that her email is generated from a 3rd party system sent to our instance. She is not composing the email manually like I am.

When I review the email log, I notice that the email bodies look quite different when I compare the email sent from the 3rd party system, and the email sent from me. Can anyone help me understand why this is failing for the second user and what we could do to make it work? 

find_real_file.png

 

 

find_real_file.png

1 ACCEPTED SOLUTION

Mike Reed1
Giga Contributor

Hi all, 

 

in case anyone comes across this in the future, I was able to fix this with scripting. emails coming from the 3rd party system were not keeping the formatting, so I had to adjust the script to handle this. 

View solution in original post

6 REPLIES 6

Ct111
Tera Sage

Without looking at script it is difficult to comment. However, I am attaching few useful links with respect to how value is fetched and how you can compare for undefined and then place value accordingly.

Link :

1) https://docs.servicenow.com/bundle/quebec-servicenow-platform/page/administer/notification/reference/r_SetFieldValsFromTheEmailBody.html

2) https://docs.servicenow.com/bundle/rome-servicenow-platform/page/administer/notification/reference/r_InboundEmailActionExamples.html

 

Mark my Answer as Correct and Helpful if it helps

Mike Reed1
Giga Contributor

Hello, I don't think the problem is with the script, or maybe it is, forgive me if I didn't categorize my post correctly. The script works when I send the email. The script doesn't work with the email sent by another user. I think it's an email format issue? I'm not sure. I've already reviewed those two links you included and I'm not seeing a solution to my problem. Let me know if I can provide any additional information

Mike Reed1
Giga Contributor

I think the problem is that the email formatting is getting dropped in the email from the 3rd party system, and variables aren't on their own line in the inbound email. I need to figure out a way to get the email formatting from the 3rd party system to put each variable on its own line. I switched the script to put the email.body_text in the additional comments variable to see what ServiceNow was seeing. find_real_file.pngfind_real_file.pngfind_real_file.png

Mike Reed1
Giga Contributor

Hi all, 

 

in case anyone comes across this in the future, I was able to fix this with scripting. emails coming from the 3rd party system were not keeping the formatting, so I had to adjust the script to handle this.