assystETM - importing email need string from mailbody
Hi,
we are reading mails from monitoring-tools in order to create new tickets. The CI/itemA of the new ticket is found in the mailbody.
How can we extract the mailbody text ? I need this text ‘oem-12.dcc.562.com’ Example of text in the mailbody: Subject: EM Event.d.d9. Please check log for details.
Host=oem-12.dcc.562.com
Target type=blbaopdf ..
Thanks for help Marion
Page 1 / 1
We use the ETM to read mailboxes with the following code to pull the body.
If the format of the inbound always remains the same, you could use a regex expressions to search the body for matches. The regex below has been substituted to work with your example string, but our looks something like….
var bodyText = String(inbound.emailBody) var regEx = /=a-z]{3}{-][0-9]{2}{.][a-z]{3}{.][0-9]{3}{.][com]{3}/; var matches = regEx.exec(bodyText);
if(matches){ // Do something interesting } else { // Do nothing }
…if not then maybe use indexOf to find “Host=” and pull x number of characters that follow.
Hello Steve,
do you now a solution with your code to get the name after the Host= as output?
So if we got Host=oem-12.dcc.562.com in our mail body, the output should be oem-12.dcc.562.com.
Our problem is that the names can be structured differently.
Examples:
- Host=oem-12.dcc.562.com
- Host=HSTG-20887.TG
- Host=Kernel.On-5489
The only thing we have in common is that we don't have spaces in our Hostnames.
Kind regards
Jo Schmitz
I recommend using https://regex101.com/ to experiment with Regular Expressions. Use ‘the ECMAScript’ option to get the same behavior as ETM.
you can use
var regEx = Host=(=^\s]+)
Which says ‘match Host= anything up to the first whitespace character, and “capture” the bit (“group”) after the =
This solution (build by your tips) works perfektly:
var content = inbound['text/plain'] var re = /Host=([^\s]+)/; var matches = content.match(re); var host = matches && matches[1] host
Many many thanks.
Kind regards
Jo Schmitz
One more Question:
I try to set the result to upper cases.
host.toUpperCase()
Error: ECMAException - TypeError: null has no such function "toUpperCase"
Do you know another function?
Could’t you also tell me wich language the ETM exactly uses?
It’s not the JAVA I know.
Kind regards
Jo Schmitz
It’s javascript/ECMA Script. What I suspect is happening is that you have an email without a Host entry. In that case matches will be null and so will host.
Calling a method (e.g. toUpperCase) on null will result is that error.
I usually just do some string magic with javascript to get that from the email body, when the email body will be the same for every email processed by the channel.
For example, I have one where i need to set the item for the ticket based on data from the body of the email below, between the “Bookings Subject:” text and the “Bookings Appointment Detail:” text.
To do so, I first create a variable to “clean” the body of the email by removing all html tags, etc.
Then I do the following, to find the start and end of the data I need. varFindItemStart finds the index of the text before the data I want, “Bookings Subject:” varFindItemEnd finds the the index of the text at the end of the data I want, “Bookings Appointment Detail.”
Now that I have these two numbers, I create another Variable to parse the text between those two index values using substring.
Now that I have the value I need from between “Bookings Subject:” text and the “Bookings Appointment Detail:”, I created a lookup table of the possible values and the corresponding Item Shortcode.
Then I create a Variable Lookup using this lookup table, where I pass the value I created in the varGetItem variable to the lookup, which returns the Item SC for that lookup value. I then use the new variable, varFindItem as the Shortcode for the Item.
It is very convoluted and there’s probably a much easier way to do it, but it works for me and it’s easy to use again, you just have to swap out the “start text” and “end text” values and it will pull everything in between.
So in your case, you would set the varFindItemStart to:
variables.varCleanDesc.indexOf('Host=')+5
and the varFindItemEnd to:
variables.varCleanDesc.indexOf('Target type=')
so then in your varGetItem variable, you would set it to: