- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2022 08:34 AM
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:
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.
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.
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?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2022 10:48 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2022 09:50 AM
Hello Mike,
Could you please share how did you fix this via script. We have faced a similar problem recently.
We have some alerts from solarwinds for which declared inbound action retrieves the value corresponding to key as undefined. When we copy the email content and send it via my outlook it processed the code correctly.
Thanks,
Urbishnu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2022 10:13 AM
Hello Urbishnu,
Yes, I can share the script with you.
The problem was that the emails, even though they looked the same being sent, had different formatting when processed in ServiceNow (as you can see in the screenshots in the original post).
To fix this, I created a variable "finalem4", and that variable was set to the correct format, regardless of the way the email came in (manual, or automatically from our HR system UKG).
var emtext = email.body_text;
var slug = emtext.substring(emtext.indexOf('Email Address:') + 15);
var finalem = slug.slice(0,slug.lastIndexOf('Supervisor:'));
var finalem2 = finalem.slice(0,finalem.lastIndexOf('<')).trim();
var finalem3 = emtext.substring(emtext.indexOf('Email Address:') + 15);
var finalem4 = "";
if(emtext.includes('<mailto')) finalem4 = finalem2; else finalem4 = finalem;
Then I set the additional comments field = finalem4 and confirmed it worked both ways.
//cart.setVariable(item, 'additional_comments', finalem4);
Your script will very likely look different than mine, but the key take away for you should be that the final variable you want to assign to a field will need to be setup to handle different email formats with an "If" function as I did above. Let me know if you need more in depth explanations of each of the variables above that I needed to make for this to work.