Create a customer by coding automatically

Moderator: crythias

Locked
ndhvu275
Znuny advanced
Posts: 139
Joined: 06 Nov 2012, 09:02
Znuny Version: 3.x, 4.x and 5.x
Real Name: Vu Nguyen
Company: INFOdation
Location: Netherlands
Contact:

Create a customer by coding automatically

Post by ndhvu275 »

Hi everyone,

I'm running OTRS 3.2.rc1 version (lasted version, notice: improve performance of customer processing...). I'm using postmaster filter to create a ticket when get an incoming email. Beside, the requirement is the system can create a new customer automatically during ticket creation (customer information includes in incoming email). Btw, I have to develop in System/PostMaster/NewTicket.pm, this file is implement to create a ticket by postmaster

Then, I inputed the coding as below:

Code: Select all

$Self->{DBObject}->Do(
			SQL  => "INSERT INTO customer_user "
			."(login, email, customer_id, pw, create_time, create_by, change_time, change_by, valid_id, first_name, last_name, street, zip, mobile, phone, city)"
			." VALUES ('".$login."', '".$email."', '".$customerId."', '".$password."', now(), 1, now(), 1, 1, '".$customerName
			."', ' ', '".$street."', '".$postcode."', '".$mobile."', '".$phone."', '".$woonplaats."')"
		);
Restart httpd
Run test, successful. But I had no see any customer is created in Customer Admin page. However, check in DB, 1 record was created in customer_user table
Then, I went to bin/ folder, and implement deletecache, refresh Customer Admin page, the result like my expecting is existed that customer.

I saw in coding customer creation, Before customer creation, must create a session, cookie for that. So I assume the system will use this session and cookie to display. If I was right, how to create a session and cookie in coding of postmaster

How to reuse the coding of customer creation in Customer Admin page.

Thanks & regards,

Vu Nguyen
OTRS 3.x, 4.x on CentOS/Windows
MySQL database
External customer backend with MySQL, MSSQL
Customization
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Create a customer by coding automatically

Post by crythias »

several things:
1) You probably do NOT want to create customers automatically from emails because you'll have a lot of viagra selling customers
2) You should be using the API and not direct database manipulation to add customers.
3) If you're not using the OTRS database back end for customers, (for instance, LDAP or another backend), your code is writing to the wrong back end.
4) if your back end (for instance, ldap) is read only, you can't write to it anyway.
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
Locked