Monday, June 28, 2010

Tracking Customer Companies in OTRS.

I have been playing abound with OTRS for the past few days and ran into a bit of a snag.  I installed it from the Ubuntu repositories but noticed that the Customers can't be linked to the Companies witch would be a useful feature.  I also found out after some digging that there was no option in the SysConfig to fix this.  I found the setting by manually editing the config files but this was of limited use.  In the end I had to make a few manual edits to make the system work as expected.  I outlined the changes below to the base 2.4.7 install.

First open a terminal and cd to your otrs install directory.
cd /usr/share/otrs

Enable CustomerCompanySupport
sudo vim Kernel/Config.pm
Add the following line inside the sub Load method.
# Enable Customer Company linking.
$Self->{CustomerUser}->{CustomerCompanySupport} = 1;

Run the mysql client and add a field to the customer table.
mysql -u root -p
use otrs2;
alter table customer_user add column company_id varchar(100);
exit

Register the extra row with the editor.
sudo vim Kernel/Config/Defaults.pm
Find the CustomerUser variable and then the Map array within it.  Add the following line after the UserCustomerID field.
[ 'UserCompanyID',  'CompanyID',  'company_id',  0, 1, 'var', '', 0 ],

Change the company dropdown list to trigger on the new CompanyID field.
sudo vim Kernel/Modules/AdminCustomerUser.pm
Look for the reference to UserCustomerID and change it to UseCompanyID. It should look like this now.
$Entry->[0] =~ /^UserCompanyID$/i

Change the dispaly logic to match against the new CompanyID.
sudo vim Kernel/System/CustomerUser.pm
Look for the reference to UserCustomerID and change it to UseCompanyID. It should look like this now.
CustomerID => $Customer{UserCompanyID},

You can now restart apache and the changes should show up.
sudo /etc/init.d/apache2 restart