[SOLVED] Extracting email body information into Dynamic fields

Moderator: crythias

Post Reply
kongyong92
Znuny newbie
Posts: 43
Joined: 15 Sep 2017, 11:40
Znuny Version: OTRS v5.0.10
Real Name: Kong-Yong
Company: Rhenus Logistics

[SOLVED] Extracting email body information into Dynamic fields

Post by kongyong92 »

Hello,

I am new to OTRS here and hopefully someone can help me with this.

There is a service from HQ that will be sending structured emails to our OTRS set up.

The email body content would be as such:

Field A: Information A
Field B: Information B
Field C: Information C
Field D: Information D

I have already created dynamic fields for Fields A to D.

Are there any ways to filter and extract out the information A to D and have them entered into the dynamic fields of the ticket automatically?

Any suggestions/help will be greatly appreciated!! :)
Last edited by kongyong92 on 11 Apr 2019, 04:47, edited 1 time in total.
Best regards,
Kong-Yong
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Extracting email body information into Dynamic fields

Post by reneeb »

You can use https://opar.perl-services.de/dist/Enha ... lter-5.0.2 (that will be included in OTRS6). That way you can use named captures in the postmaster filter (see description of the addon)
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
kongyong92
Znuny newbie
Posts: 43
Joined: 15 Sep 2017, 11:40
Znuny Version: OTRS v5.0.10
Real Name: Kong-Yong
Company: Rhenus Logistics

Re: Extracting email body information into Dynamic fields

Post by kongyong92 »

reneeb wrote:You can use https://opar.perl-services.de/dist/Enha ... lter-5.0.2 (that will be included in OTRS6). That way you can use named captures in the postmaster filter (see description of the addon)
Thanks for the suggestion!

But it is not working 100% for me right now.

I am only able to extract out the information from the first line but not the rest.

Unfortunately, all the information that are to be extracted out are captured in the email body. Any idea on how I should go about doing it?

Right now I am doing the following:

Check email header: Body
(Field 1: (?<eg1>\d+)|Field 2: (?<eg2>\d+)|Field 3: (?<eg3>\d+))

Set email header:
Dynamic field 1: [**\eg1**]
Dynamic field 2: [**\eg2**]
Dynamic field 3: [**\eg3**]
Best regards,
Kong-Yong
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Extracting email body information into Dynamic fields

Post by reneeb »

You use alternations in the regex. So it stops when the first part matched (in this case it's the "Field 1: (?<eg1>\d+)" part). Try this regex:

Code: Select all

(Field 1: (?<eg1>\d+)\s+Field 2: (?<eg2>\d+)\s+Field 3: (?<eg3>\d+))
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
kongyong92
Znuny newbie
Posts: 43
Joined: 15 Sep 2017, 11:40
Znuny Version: OTRS v5.0.10
Real Name: Kong-Yong
Company: Rhenus Logistics

Re: Extracting email body information into Dynamic fields

Post by kongyong92 »

reneeb wrote:You use alternations in the regex. So it stops when the first part matched (in this case it's the "Field 1: (?<eg1>\d+)" part). Try this regex:

Code: Select all

(Field 1: (?<eg1>\d+)\s+Field 2: (?<eg2>\d+)\s+Field 3: (?<eg3>\d+))
Dear reneeb,

Thanks for the reply.

I tried but it don't seem to work though. :(

Any idea why? Below is the information that I've entered:

Code: Select all

Check email header: Body
(PO: (?<PO>\d+)\s+VENDOR: (?<V>\d+)\s+HOI_INDICATOR: (?<H>\d+)\s+LOAD_PORT: (?<L>\d+))

Code: Select all

Set values:
[**\PO**]
[**\V**]
[**\H**]
[**\L**]
Best regards,
Kong-Yong
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Extracting email body information into Dynamic fields

Post by reneeb »

Can you provide a sample mail?
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
kongyong92
Znuny newbie
Posts: 43
Joined: 15 Sep 2017, 11:40
Znuny Version: OTRS v5.0.10
Real Name: Kong-Yong
Company: Rhenus Logistics

Re: Extracting email body information into Dynamic fields

Post by kongyong92 »

reneeb wrote:Can you provide a sample mail?
Yes sure, apologies, realized that I have missed that out.

Kindly refer below:

PO: 4500255891
VENDOR: ABC COMPANY Import & Export
HOI_INDICATOR: ABC
LOAD_PORT: CNSHA
PLAN_RCV_DT: 2018/01/09 <--i have excluded this for now due to the 100 characters limit in the textbox
PLAN_PSI_DT: 2017/11/16 <--i have excluded this for now due to the 100 characters limit in the textbox
Best regards,
Kong-Yong
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Extracting email body information into Dynamic fields

Post by reneeb »

This works:
You do not have the required permissions to view the files attached to this post.
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
kongyong92
Znuny newbie
Posts: 43
Joined: 15 Sep 2017, 11:40
Znuny Version: OTRS v5.0.10
Real Name: Kong-Yong
Company: Rhenus Logistics

Re: Extracting email body information into Dynamic fields

Post by kongyong92 »

Dear reneeb,

Thank you soooo much for the assistance! It works! :)

Last question: Do you have a list of references in order to better understand and write those regular expressions? A link/reference guide will be greatly appreciated! :)
Best regards,
Kong-Yong
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Extracting email body information into Dynamic fields

Post by reneeb »

Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
kongyong92
Znuny newbie
Posts: 43
Joined: 15 Sep 2017, 11:40
Znuny Version: OTRS v5.0.10
Real Name: Kong-Yong
Company: Rhenus Logistics

Re: Extracting email body information into Dynamic fields

Post by kongyong92 »

Best regards,
Kong-Yong
kongyong92
Znuny newbie
Posts: 43
Joined: 15 Sep 2017, 11:40
Znuny Version: OTRS v5.0.10
Real Name: Kong-Yong
Company: Rhenus Logistics

Re: Extracting email body information into Dynamic fields

Post by kongyong92 »

Dear reneeb,

Any ideas if the function is able to capture information from the email subject and email body simultaneously?

For e.g.

Email subject: 93928320/9392 <-- i want to only capture 9392 i.e. number after the forward slash "/" as the customer ID.

Email body: as per the conversation above.

Is this possible? or am i able to only perform named captures from either the email Subject or email Body only?
Best regards,
Kong-Yong
kongyong92
Znuny newbie
Posts: 43
Joined: 15 Sep 2017, 11:40
Znuny Version: OTRS v5.0.10
Real Name: Kong-Yong
Company: Rhenus Logistics

Re: Extracting email body information into Dynamic fields

Post by kongyong92 »

I tried the following reg exp but not too sure how i can integrate the named capture component into it.

Code: Select all

([^\/]+)\/?$
I used the following text as an example:
4500253107/113086 <- trying to extract only 113086 and set it as the customer ID
Best regards,
Kong-Yong
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Extracting email body information into Dynamic fields

Post by reneeb »

Code: Select all

\d+\/(?<customer>\d+)
and then use

Code: Select all

[**\customer**]
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
kongyong92
Znuny newbie
Posts: 43
Joined: 15 Sep 2017, 11:40
Znuny Version: OTRS v5.0.10
Real Name: Kong-Yong
Company: Rhenus Logistics

Re: Extracting email body information into Dynamic fields

Post by kongyong92 »

Dear reneeb,

As always, thank you so much for your help.

I've tried and it seems that the customer ID is not overwritten though.

We have an automated system (ABC@system.com) sending daily emails to OTRS with the customer ID included.

ABC@system.com is registered in our customer module.

When the email is received, the customer ID remains the ID of ABC@system.com.

The system somehow does not overwrite this ID number.

=====================================
To better illustrate the situation:
ABC@system.com (registered customer in the customer module with CustomerID 123456) sends email to OTRS:

Email subject: 12345679/99999 <-- i want to capture 99999 as customer ID and overwrite 123456.

Hopefully, this would then link the ticket directly to the customer based on the customer ID.

Is this possible?
Best regards,
Kong-Yong
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Extracting email body information into Dynamic fields

Post by reneeb »

Which X-OTRS-Header did you set? X-OTRS-CustomerNo? Are there any other postmaster filters that set the customer id?
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
kongyong92
Znuny newbie
Posts: 43
Joined: 15 Sep 2017, 11:40
Znuny Version: OTRS v5.0.10
Real Name: Kong-Yong
Company: Rhenus Logistics

Re: Extracting email body information into Dynamic fields

Post by kongyong92 »

Dear reneeb,

Yes, I used X-OTRS-CustomerNo.

There are no other filters that set this field.
Best regards,
Kong-Yong
wucherpfennig
Znuny newbie
Posts: 23
Joined: 11 Apr 2017, 14:15
Znuny Version: 5.0.18

Re: Extracting email body information into Dynamic fields

Post by wucherpfennig »

Hi everyone

This is indeed a very helpful and interesting thread...! Thank you for sharing this information.

Is there a way to achieve such a solution WITHOUT the need of installing a third party module?
As the documentation states there should be an option to put some postmaster filters into the config.pm or something similar... but I did not find any examples to achieve a more complex solution (multi match search and multi set like in the example above).

So if anybody could guide me in the right direction that would help me a lot!

Any feedback is highly appreciated!

best regards

wucherpfennig
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Extracting email body information into Dynamic fields

Post by reneeb »

Then you have to wait for OTRS 6. The addon was integrated into the framework...
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
muellotrs
Znuny newbie
Posts: 7
Joined: 18 Oct 2017, 11:50
Znuny Version: 5.0.0.0.0

Re: Extracting email body information into Dynamic fields

Post by muellotrs »

If Postmaster is not enough get the latest Ticket Article with an API call tiggered through a ticket event (even during the ticket workflow)
XSLT incoming mapping:
<TicketID><xsl:value-of select="//TicketID"/></TicketID>
<AllArticles>1</AllArticles>
<ArticleOrder>DESC</ArticleOrder>
<ArticleLimit>1</ArticleLimit>

XSLT outgoing mapping:
<TicketID><xsl:value-of select="//Article/Body"/></TicketID>
<TicketNumber><xsl:value-of select="//TicketNumber"/></TicketNumber>
Last edited by muellotrs on 23 Jan 2018, 20:18, edited 1 time in total.
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Extracting email body information into Dynamic fields

Post by reneeb »

That is an API call, not the postmaster filter! And that post doesn't fit the question at all...
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
kongyong92
Znuny newbie
Posts: 43
Joined: 15 Sep 2017, 11:40
Znuny Version: OTRS v5.0.10
Real Name: Kong-Yong
Company: Rhenus Logistics

Re: Extracting email body information into Dynamic fields

Post by kongyong92 »

kongyong92 wrote:Dear reneeb,

Yes, I used X-OTRS-CustomerNo.

There are no other filters that set this field.
Anyone has an idea for this? any way that we can overwrite the field?
Best regards,
Kong-Yong
kongyong92
Znuny newbie
Posts: 43
Joined: 15 Sep 2017, 11:40
Znuny Version: OTRS v5.0.10
Real Name: Kong-Yong
Company: Rhenus Logistics

Re: Extracting email body information into Dynamic fields

Post by kongyong92 »

kongyong92 wrote:
kongyong92 wrote:Dear reneeb,

Yes, I used X-OTRS-CustomerNo.

There are no other filters that set this field.
Anyone has an idea for this? any way that we can overwrite the field?

It seems to work fine now!

Only pending issue is that the customer information section is not overwritten.
Best regards,
Kong-Yong
kongyong92
Znuny newbie
Posts: 43
Joined: 15 Sep 2017, 11:40
Znuny Version: OTRS v5.0.10
Real Name: Kong-Yong
Company: Rhenus Logistics

Re: Extracting email body information into Dynamic fields

Post by kongyong92 »

kongyong92 wrote:
kongyong92 wrote:
kongyong92 wrote:Dear reneeb,

Yes, I used X-OTRS-CustomerNo.

There are no other filters that set this field.
Anyone has an idea for this? any way that we can overwrite the field?

It seems to work fine now!

Only pending issue is that the customer information section is not overwritten.
Hi reneeb,

Is there anyway to set the customer user based on the customer ID?
Assuming there's one customer user to each customer ID.
Best regards,
Kong-Yong
Post Reply