Is it possible, and if so how, to add custom attributes to the ticket object in OTRS? I would like to implement two drop down lists where the values of the second list would depend on the selection in the first list. I have looked into this and I don't believe this can be done using dynamic fields functionality.
Currently I have succeeded in creating a drop down list within the AgentTicketCompose view using external data. Please view the code below for my changes. Now I would like to store the selected value in the database by adding a custom attribute.
I would also like to know how I can use the CustomerID value of a ticket in my custom kernel package. Currently the query is using a manual customer ID of 3. This must be the value of the CustomerID assigned to a ticket. How can I achieve this.
- Created a new kernel package for dotProject functionality:
Kernel/System/DotProject.pm
Code: Select all
package Kernel::System::DotProject; use strict; use warnings; use Kernel::System::DB; sub new { my ( $Class,%Param ) = @_; my $Self = bless {}, $Class; # get needed objects for my $Needed (qw(ConfigObject EncodeObject LogObject MainObject DBObject)) { die "Got no $Needed!" if !$Param{$Needed}; $Self->{$Needed} = $Param{$Needed}; } for my $Object ( qw(LogObject ConfigObject EncodeObject) ) { $Self->{$Object} = $Param{$Object} or die "Need $Object!"; } $Self->{DBObject} = Kernel::System::DB->new( %{$Self}, DatabaseDSN => 'DBI:mysql:database=<name>;host=<host>', DatabaseUser => '<user>', DatabasePw => '<pass>', ); return $Self; } # ProjectList returns a hash with all projects in dotProject sub ProjectList { my ($Self) = @_; my $SQL = 'SELECT project_id, project_name FROM projects WHERE project_company = 3'; return if !$Self->{DBObject}->Prepare( SQL => $SQL, ); my %List; while ( my @Row = $Self->{DBObject}->FetchrowArray() ) { $List{ $Row[0] } = "$Row[1]"; } return %List; } 1;
- Modified the controller for the AgentTicketCompose view.
Kernel/Modules/AgentTicketCompose.pm
Inserted new line on line 28 to include the new kernel package.
Inserted new line on line 58 to create new instance of the DotProject object (not entirely sure not familiar with Perl).Code: Select all
use Kernel::System::DotProject;
Inserted code to generate contents for the drop down list on line 1449. I did this within the "sub _Mask" part.Code: Select all
$Self->{DotProjectObject} = Kernel::System::DotProject->new(%Param);
Code: Select all
# project list from DotProject my %DotProjectProjectList = $Self->{DotProjectObject}->ProjectList(); $Param{DotProjectProjectSelect} = $Self->{LayoutObject}->BuildSelection( Name => 'DotProjectID', Data => \%DotProjectProjectList, PossibleNone => 1, );
- Modified the view to get drop down list
Kernel/Output/HTML/Standard/AgentTicketCompose.dtl
Inserted code to generate drop down list on line 364.
Code: Select all
<label for="DotProjectProject">Project:</label> <div class="Field"> $Data{DotProjectProjectSelect} </div> <div class="Clear"></div>