How to fetch a substring from a string from an email body
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2022 08:25 AM
Hi All,
i actually need to retrieve a substring from a string and that too from a email body, and all this is related to inbound email actions where the email is triggered from a tool to our instance and from there i need to retrieve
For example: In the email body we have the below data for Configuration and Description and we need to fetch only 'ZSNH36TJ50-000YT-100YDT' from configuration
Configuration : ZSNH36TJ50-000YT-100YDT in New Jersey, USA
Description:Power is down
The script i used
if (email.body.configuration != undefined)
var res = email.body.configuration;
var sec=res.substring(0,24);
But neither the string in configuration is getting fetched nor substring is fetched
Could you please help me with the code
Thanks and Regards,
Sandeep

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2022 08:42 AM
Hi,
What you have, should work, it's most likely due to a format issue, if what you've pasted is the true way it's coming across in the email, then you have extra spaces there that break the email variable, I believe.
Configure_:_ZSNH36TJ50-000YT-100YDT in New Jersey, USA
When used in background script, it does work:
Consider adding a log statement to your inbound action so you can check the value of email.body.configuration, etc. such as:
gs.info("***DEBUG - Email variable Configuration is: " + email.body.configuration);
Then look for it in your system logs and see what it says.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2022 08:51 AM
Hi Allen,
I too have tried in the background scripts and its working there.
But the problem is the email is triggered from a tool of the client and the format of the Configuration is standard with spaces before and after :(colon) and the string wont have have quotes " " as well in the email
Could you please help how to go ahead now
Thanks and Regards,
Sandeep

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2022 09:05 AM
Hi,
The quotes is only for coding purposes and doesn't need to be there.
To be a realist here, it's a bit off that the format for the "Description" is what you'd expect, but for "Configuration", it's not. So it looks like your "tool" could...do it the way you want, but perhaps, you're just unable to correct that? Or maybe you mistated the format of "Description" here in your post and both are wrong?
Either way, as was mentioned, please use a log statement to see what you're getting, chances are, it's not correct.
With that said, you'd have to review alternative approaches such as...using regex (like mentioned below...or...try:
var res = email.body_text.split("Configuration : ")[1].split(" ")[0];
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2022 09:16 AM
Hi,
For Description:Power is down, there is no space but for Configuration : ZSNH36TJ50-000YT-100YDT in New Jersey, USA thers is space as you can see, i copied and pasted the same thing here.
The script is showing an error when i pasted in the inbound email action.
Should i add any line before it?