[SOLVED] Change CustomerID depending on Mail-From

Moderator: crythias

Locked
binerf
Znuny newbie
Posts: 20
Joined: 25 Oct 2012, 06:43
Znuny Version: 3.1.10

[SOLVED] Change CustomerID depending on Mail-From

Post by binerf »

Hi all,

I'm sorry if this question has already been replied but I've searched on this forum and didn't get answer... my configuration might be weird.

I would like to configure OTRS to add automatically the CustomerID in a ticket when it receives a new email request; is it possible ?

In addition, I use Cstomer Company feature and external customers/companies DB.
OTRS version is 3.1.10.

Thank you in advance.

Best
Last edited by binerf on 31 Oct 2012, 05:13, edited 1 time in total.
jojo
Znuny guru
Posts: 15020
Joined: 26 Jan 2007, 14:50
Znuny Version: Git Master
Contact:

Re: Change CustomerID depending on Mail-From

Post by jojo »

the customerID is assigned based on the data in the customer DB
"Production": OTRS™ 8, OTRS™ 7, STORM powered by OTRS
"Testing": ((OTRS Community Edition)) and git Master

Never change Defaults.pm! :: Blog
Professional Services:: http://www.otrs.com :: enjoy@otrs.com
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Change CustomerID depending on Mail-From

Post by crythias »

Explicitly: the customer must be in your database and have assigned a CustomerID.
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
binerf
Znuny newbie
Posts: 20
Joined: 25 Oct 2012, 06:43
Znuny Version: 3.1.10

Re: Change CustomerID depending on Mail-From

Post by binerf »

Sorry, it doesn't work for me.

My user is present in my external customers/companies DB.
I can read information about this user via OTRS interface and associted company information also (CustomerID is company_test).
But when my user sends an email to otrs email address, the ticket is created with user email address (mail-from) as CustomerID.

Did I miss something ?

Oh, by the way, I've no valid/invalid field in my customer DB.

Thank you,
Best
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: Change CustomerID depending on Mail-From

Post by reneeb »

Can you check if the user data contain a field named UserCompanyID?

You can use the following perl script (save it as "ps.FindCustomerUser.pl" in <OTRS_HOME>/bin).

Code: Select all

#!/usr/bin/perl -w

use strict;
use warnings;

use File::Basename;
use FindBin qw($RealBin);
use lib dirname($RealBin);
use lib dirname($RealBin) . "/Kernel/cpan-lib";

use Kernel::Config;
use Kernel::System::Encode;
use Kernel::System::Log;
use Kernel::System::Time;
use Kernel::System::Main;
use Kernel::System::DB;
use Kernel::System::CustomerUser;

use Data::Dumper;

# create common objects
my %CommonObject = ();
$CommonObject{ConfigObject} = Kernel::Config->new(%CommonObject);
$CommonObject{EncodeObject} = Kernel::System::Encode->new(%CommonObject);
$CommonObject{LogObject}
    = Kernel::System::Log->new( %CommonObject, LogPrefix => 'otrs.AddCustomerUser.pl' );
$CommonObject{TimeObject} = Kernel::System::Time->new(%CommonObject);
$CommonObject{MainObject} = Kernel::System::Main->new(%CommonObject);
$CommonObject{DBObject}   = Kernel::System::DB->new(%CommonObject);
$CommonObject{UserObject} = Kernel::System::CustomerUser->new(%CommonObject);

my %List = $CommonObject{UserObject}->CustomerSearch(
    PostMasterSearch => $ARGV[0],
);

for my $User ( keys %List ) {
    my %Data = $CommonObject{UserObject}->CustomerUserDataGet(
        User => $User,
    );

    delete $Data{CompanyConfig};
    delete $Data{Config};

    print Dumper \%Data;
}
Example (nr of fields and fieldnames may vary):

Code: Select all

$ sudo perl ps.FindCustomerUsr.pl bad.max@test.tld
$VAR1 = {
          'ValidID' => '1',
          'UserEmail' => 'bad.max@test.tld',
          'UserRefreshTime' => '',
          'UserID' => '5949',
          'UserCustomerID' => 'company_test',
          'UserName' => 'BADMAX01',
          'UserFirstname' => 'Bad',
          'UserOE' => 'HR',
          'UserSalutation' => 'Herr',
          'Source' => 'CustomerUser',
          'UserTitle' => '',
          'UserLastname' => 'Max',
          'UserUserID' => '7342385',
          'UserShowTickets' => '25',
          'UserLogin' => '5949',
          'UserOrganisation' => 'VDSG',
          'UserPhone' => '1234567',
          'UserLocation' => 'Bahamas',
          'Valid' => 'valid'
        };
The postmaster searches for the user with the given mail address. If it finds one, it sets the customer-no with the value of UserCustomerID. If no UserCustomerID is given or no customer is found the CustomerID is set to the mail address of the sender.
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
binerf
Znuny newbie
Posts: 20
Joined: 25 Oct 2012, 06:43
Znuny Version: 3.1.10

Re: Change CustomerID depending on Mail-From

Post by binerf »

Here the result:

Code: Select all

/opt/otrs/bin # perl ps.FindCustomerUser.pl email_user@domain.com
DBD::mysql::st execute failed: Unknown column 'valid_id' in 'where clause' at /opt/otrs/Kernel/System/DB.pm line 618.
ERROR: otrs.AddCustomerUser.pl-10 Perl: 5.10.1 OS: linux Time: Tue Oct 30 17:41:20 2012

 Message: Unknown column 'valid_id' in 'where clause', SQL: 'SELECT CONT_USERNAME , CONT_FIRST_NAME, CONT_FIRST_NAME, CONT_CODESAGE, CONT_EMAIL FROM CONTACTS WHERE  LOWER(CONT_EMAIL) LIKE LOWER('email_user@domain.com')   AND valid_id IN (1)  LIMIT 250'

 Traceback (9886): 
   Module: Kernel::System::CustomerUser::DB::CustomerSearch (v1.88.2.1) Line: 312
   Module: Kernel::System::CustomerUser::CustomerSearch (v1.63.2.1) Line: 189
   Module: ps.FindCustomerUser.pl (unknown version) Line: 32
/opt/otrs/bin #
Problem with valid_id ?
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: Change CustomerID depending on Mail-From

Post by reneeb »

What does the CustomerUser-Map in you Kernel/Config.pm look like? Is there anywhere "valid_id" mentioned?
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
binerf
Znuny newbie
Posts: 20
Joined: 25 Oct 2012, 06:43
Znuny Version: 3.1.10

Re: Change CustomerID depending on Mail-From

Post by binerf »

Okay, I found my error with your help.

I've kept this line

Code: Select all

CustomerValid          => 'valid_id',
in my Config.pm file.

I've commented it and everything works.

Many thanks !!!
Locked