[SOLVED] PostMaster Filter by department

Moderator: crythias

Post Reply
zip
Znuny advanced
Posts: 103
Joined: 02 Jan 2014, 12:32
Znuny Version: 5.0.9

[SOLVED] PostMaster Filter by department

Post by zip »

Hello,

i want to filter the incoming emails by the department of the user. The users have this field:
otrs_ad.PNG
how can i filter by this value?
otrs_pf.PNG
for example, if the department of the user of the incoming mail is xy, then set the queue to xy.

thanks
You do not have the required permissions to view the files attached to this post.
Last edited by zip on 26 Jun 2015, 11:15, edited 1 time in total.
OTRS 5.0.9 - CentOS 7 - MariaDB 5.5
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: PostMaster Filter by department

Post by reneeb »

This is not possible with Postmaster filter created via the Web UI. You have to write your own Postmaster filter module.
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
zip
Znuny advanced
Posts: 103
Joined: 02 Jan 2014, 12:32
Znuny Version: 5.0.9

Re: PostMaster Filter by department

Post by zip »

ok, any help or useful links about this?

i have one more question, what does "Organization" search for? It's not possible that i set the department as organization so that the filter would work?

otrs_pf_organization.png
You do not have the required permissions to view the files attached to this post.
OTRS 5.0.9 - CentOS 7 - MariaDB 5.5
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: PostMaster Filter by department

Post by reneeb »

This searches for a email header named 'Organization' (this is not used very often)
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
zip
Znuny advanced
Posts: 103
Joined: 02 Jan 2014, 12:32
Znuny Version: 5.0.9

Re: PostMaster Filter by department

Post by zip »

i'm trying to make a own perl module but i'm stuck at one point. Since you are the perl guru, you may could give me a help about this. I'm trying to say "if the department of the user who is sending a mail is xy, then put the ticket into queue xy". How can i retireve the information of the department of the user?
i'm not sure if this piece of code is correct:

Code: Select all

		
my %User = $CustomerUserObject->CustomerUserDataGet(
            UserDepartment => 'xy',
		);
OTRS 5.0.9 - CentOS 7 - MariaDB 5.5
crythias
Moderator
Posts: 10169
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: PostMaster Filter by department

Post by crythias »

Give each department its own email address.
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
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: PostMaster Filter by department

Post by reneeb »

You have to search for the customer based on the mail address...

https://gist.github.com/reneeb/930cc513fece99dfeb67
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
zip
Znuny advanced
Posts: 103
Joined: 02 Jan 2014, 12:32
Znuny Version: 5.0.9

Re: PostMaster Filter by department

Post by zip »

crythias wrote:Give each department its own email address.
would be the easiest way and also suggested by me, but they want to do it with one email address.

thank you very much for the code.
OTRS 5.0.9 - CentOS 7 - MariaDB 5.5
zip
Znuny advanced
Posts: 103
Joined: 02 Jan 2014, 12:32
Znuny Version: 5.0.9

Re: PostMaster Filter by department

Post by zip »

in the perl module, its possible to hardcode something like

Code: Select all

$Param{GetParam}->{'X-OTRS-Service'} = 'ServiceCategory1';


its not working
tried it with debug=3 but got no errors in log
OTRS 5.0.9 - CentOS 7 - MariaDB 5.5
crythias
Moderator
Posts: 10169
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: PostMaster Filter by department

Post by crythias »

Take a look at my PostMaster Filter in my HowTo where a Param is set.
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
zip
Znuny advanced
Posts: 103
Joined: 02 Jan 2014, 12:32
Znuny Version: 5.0.9

Re: PostMaster Filter by department

Post by zip »

i have the Post Master Filter

https://gist.github.com/reneeb/930cc513fece99dfeb67

and the xml

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<otrs_config version="1.0" init="Application">
    <ConfigItem Name="PostMaster::PreFilterModule###111-SetQueueByCustomerDepartment" Required="0" Valid="0">
                <Description Translatable="1">Set queue by customer department.</Description>
        <Group>Ticket</Group>
        <SubGroup>Core::PostMaster</SubGroup>
        <Setting>
            <Hash>
                <Item Key="Module">Kernel::System::PostMaster::Filter::SetQueueByCustomerDepartment</Item>
            </Hash>
        </Setting>
    </ConfigItem>
</otrs_config>
but it wont work. Do i miss something?
OTRS 5.0.9 - CentOS 7 - MariaDB 5.5
zip
Znuny advanced
Posts: 103
Joined: 02 Jan 2014, 12:32
Znuny Version: 5.0.9

Re: PostMaster Filter by department

Post by zip »

It still not works :cry:

any help with this? :)
OTRS 5.0.9 - CentOS 7 - MariaDB 5.5
crythias
Moderator
Posts: 10169
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: PostMaster Filter by department

Post by crythias »

It has been almost an entire year. One might think you'd have a workaround on this by now. Like telling your customers to send to department-support@yourdomain.com

Still, and you should know better, we can't fix "it doesn't work."
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
zip
Znuny advanced
Posts: 103
Joined: 02 Jan 2014, 12:32
Znuny Version: 5.0.9

Re: PostMaster Filter by department

Post by zip »

The request was paused and now resumed. It has to work, its not an option to make a workaround like you suggested :)
Thx for your help, i will acquire some perl skills to solve this.
OTRS 5.0.9 - CentOS 7 - MariaDB 5.5
crythias
Moderator
Posts: 10169
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: PostMaster Filter by department

Post by crythias »

"it doesn't work" is unhelpful. Logs, error messages, what actually happens, what you think is happening is useful.

Insert log code where variables change or are initiated.
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
zip
Znuny advanced
Posts: 103
Joined: 02 Jan 2014, 12:32
Znuny Version: 5.0.9

Re: PostMaster Filter by department

Post by zip »

no logs, no errors, nothing happens :) thats the problem, i'm trying to insert log code but i'm failing:

1) I changed this line in the postmaster filter .pm file: $Self->{Debug} = 5; //or 1 or 3
does nothing, it should (i think) write in the log file which is set in config.pm:

$Self->{'LogModule'} = 'Kernel::System::Log::File';
$Self->{'LogModule::LogFile'} = 'C:/otrsQS/OTRS/var/log/otrs.log';

2) I'm trying to write to a own log file, but it still not works:

Code: Select all

open(my $fh, '>', 'C:\otrs\OTRS\Kernel\System\PostMaster\Filter\log1.txt');
print $fh "cmon ffs\n";
close $fh;
OTRS 5.0.9 - CentOS 7 - MariaDB 5.5
zip
Znuny advanced
Posts: 103
Joined: 02 Jan 2014, 12:32
Znuny Version: 5.0.9

Re: PostMaster Filter by department

Post by zip »

he does not find the customer, !%CustomerList = 1

Code: Select all

    return 1 if ( !%CustomerList || scalar keys %CustomerList > 1 );
so i guess the problem is in

Code: Select all

    # find customer based on sender mail address
    my %CustomerList = $Self->{CustomerObject}->CustomerSearch(
        PostMasterSearch => $Param{GetParam}->{From},
        UserID           => 1,
    );
i think PostMasterSearch expects a mail adress but $Param{GetParam}->{From} is like "Max Mustermann <Max.Mustermann@yourdomain.com>"
OTRS 5.0.9 - CentOS 7 - MariaDB 5.5
zip
Znuny advanced
Posts: 103
Joined: 02 Jan 2014, 12:32
Znuny Version: 5.0.9

Re: PostMaster Filter by department

Post by zip »

got it!

need to get the mail out of the string, with

Code: Select all

	my $String1= "<";
	my $String2= ">";
	my $From = $Param{GetParam}->{From};
	(my $Mail) = $From =~ /$String1(.*?)$String2/;
and then

Code: Select all

 
    # find customer based on sender mail address
    my %CustomerList = $Self->{CustomerObject}->CustomerSearch(
        PostMasterSearch => $Mail,
        UserID           => 1,
    );
thx reneeb and crythias for your help!
OTRS 5.0.9 - CentOS 7 - MariaDB 5.5
Post Reply