Change UserCustomerID in code

Moderator: crythias

Post Reply
Sattie
Znuny newbie
Posts: 3
Joined: 18 Jan 2023, 16:04
Znuny Version: 6.4.5
Real Name: Juan

Change UserCustomerID in code

Post by Sattie »

Hi my good Znuny fellas,

I'm trying to change the CustomerUserID of some existing users depending on some flags using the CustomerUser method "CustomerUserUpdate", but I'm facing an issue when trying to get it done.

I have taken as an example the call from Kernel/System/CustomerCompany/Event/CustomerUserUpdate.pm, you can see it in GitHub here -> https://github.com/znuny/Znuny/blob/dev ... rUpdate.pm.

The piece of code I'm referring to is the following

Code: Select all

$CustomerUserObject->CustomerUserUpdate(
            %CustomerData,
            ID             => $CustomerUserLogin,
            UserCustomerID => $Param{Data}->{CustomerID},
            UserID         => $Param{UserID},
);
I have reproduced the call in the following way:

Code: Select all

$UserObject->CustomerUserUpdate(
	%UserData,
         ID => $UserData{UserLogin},
         UserCustomerID => $customerID,
         UserID => $UserData{UserID}
);
Where %UserData comes from the CustomerUser method CustomerUserDataGet. Thing is when this piece of code gets executed I get the following error in the logs:
Message: Incorrect integer value: 'some_username' for column `otrs`.`customer_user`.`change_by` at row 3967, SQL: 'UPDATE customer_user SET title = ?, first_name = ?, last_name = ?, login = ?, email = ?, customer_id = ?, phone = ?, fax = ?, mobile = ?, street = ?, zip = ?, city = ?, country = ?, comments = ?, valid_id = ?, change_time = '2023-05-24 15:14:29', change_by = ? WHERE LOWER(login) = LOWER(?)'

I have realized that both $UserData{UserLogin} and $UserData{UserID} gives me the same value, which is the one for 'some_username'. Does anyone know how I can realize this call to get the proper user id in the update command? Or if there's a better way to accomplish my objective?

Thank you in advance! :)
root
Administrator
Posts: 3961
Joined: 18 Dec 2007, 12:23
Znuny Version: Znuny and Znuny LTS
Real Name: Roy Kaldung
Company: Znuny
Contact:

Re: Change UserCustomerID in code

Post by root »

Hi,

It would help to know which problem you are trying to solve.

- Roy
Znuny and Znuny LTS running on CentOS / RHEL / Debian / SLES / MySQL / PostgreSQL / Oracle / OpenLDAP / Active Directory / SSO

Use a test system - always.

Do you need professional services? Check out https://www.znuny.com/

Do you want to contribute or want to know where it goes ?
Sattie
Znuny newbie
Posts: 3
Joined: 18 Jan 2023, 16:04
Znuny Version: 6.4.5
Real Name: Juan

Re: Change UserCustomerID in code

Post by Sattie »

Hi Roy,

Sorry if I didn't make myself clear. I'm trying to change the UserCustomerID from some custom code as I explain here:
I'm trying to change the CustomerUserID of some existing users depending on some flags using the CustomerUser method "CustomerUserUpdate", but I'm facing an issue when trying to get it done.
The problem I'm trying to solve is an error that I see in the apache error log file:
Message: Incorrect integer value: 'some_username' for column `otrs`.`customer_user`.`change_by` at row 3967, SQL: 'UPDATE customer_user SET title = ?, first_name = ?, last_name = ?, login = ?, email = ?, customer_id = ?, phone = ?, fax = ?, mobile = ?, street = ?, zip = ?, city = ?, country = ?, comments = ?, valid_id = ?, change_time = '2023-05-24 15:14:29', change_by = ? WHERE LOWER(login) = LOWER(?)'
Which comes from the call to the method "CustomerUserUpdate":

Code: Select all

$UserObject->CustomerUserUpdate(
	%UserData,
         ID => $UserData{UserLogin},
         UserCustomerID => $customerID,
         UserID => $UserData{UserID}
);
So in order to solve the issue, I asked:
I have realized that both $UserData{UserLogin} and $UserData{UserID} gives me the same value, which is the one for 'some_username'. Does anyone know how I can realize this call to get the proper user id in the update command? Or if there's a better way to accomplish my objective?
Reading the error message it's obvious that the SQL UPDATE can't get executed because it's trying to insert the field "some_user" in a integer value column (`otrs`.`customer_user`.`change_by`). This is typically an user ID and that's why I mentioned that the values coming from $UserData{UserLogin} and $UserData{UserID} returns the same values, which is "some_user".

I hope this makes things clear, I'm just trying to see if someone has experience with this and can sort of guide me through the process.

Thank you in advance and pelase don't hesitate to ask me if the problem is not clear! :D
Post Reply