Add custom attributes to ticket without using dynamic fields

Moderator: crythias

Post Reply
hvosdrecomm
Znuny newbie
Posts: 8
Joined: 08 Aug 2012, 11:38
Znuny Version: 3.1.7
Real Name: Hans Vos
Company: Drecomm

Add custom attributes to ticket without using dynamic fields

Post by hvosdrecomm »

Hello,

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.

    Code: Select all

    use Kernel::System::DotProject;
    Inserted new line on line 58 to create new instance of the DotProject object (not entirely sure not familiar with Perl).

    Code: Select all

    $Self->{DotProjectObject} = Kernel::System::DotProject->new(%Param);
    Inserted code to generate contents for the drop down list on line 1449. I did this within the "sub _Mask" part.

    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>
I now have a drop down box populated with a list of projects. Next step is to find a way to store this information with a ticket using AJAX and use the project ID to generate the second drop down list. First I need to know how to add custom attribute and store the value. Any help is greatly appreciated.
OTRS 3.1.7, Ubuntu Server 12.04 LTS, MySQL
crythias
Moderator
Posts: 10169
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Add custom attributes to ticket without using dynamic fi

Post by crythias »

The answer is to use dynamic fields to store the data.

I already mentioned this in previous posts. Just because dynamic fields don't allow dependency, that isn't a reason they can't store data.
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
hvosdrecomm
Znuny newbie
Posts: 8
Joined: 08 Aug 2012, 11:38
Znuny Version: 3.1.7
Real Name: Hans Vos
Company: Drecomm

Re: Add custom attributes to ticket without using dynamic fi

Post by hvosdrecomm »

Hi,

We have indeed decided that using dynamic fields is the way to go. I have duplicated the files from the "drop down" dynamic field type to make our own. Is there any documentation how to create your own dynamic field type? Instead of manually adding our values for the drop down list I have the drop-down box to be populated using a result set from a MySQL query.

Kind regards,

Hans Vos
OTRS 3.1.7, Ubuntu Server 12.04 LTS, MySQL
crythias
Moderator
Posts: 10169
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Add custom attributes to ticket without using dynamic fi

Post by crythias »

hvosdrecomm wrote:Is there any documentation how to create your own dynamic field type?
http://doc.otrs.org/3.1/en/html/adminar ... ields.html
http://doc.otrs.org/3.1/en/html/dynamic ... ation.html

All major input types are supported for dynamic fields in the interface. But don't let that stop you. It's an HTML field. Anything you want to do to assign a value to an HTML field you can do.
edit the .dtl and make sure you apply the DynamicField name to the input type you wish.

http://www.w3schools.com/html/html_forms.asp

Even if you "create" the field as a ... I don't know.. textbox? you can fill the value with anything that you want, as long as it conforms to the type of data (size, VarChar/Int/Float, for example) you have created the dynamic field for. (It doesn't necessarily make sense to apply a text string as a value to a checkbox, for instance).

Instead of manually adding our values for the drop down list I have the drop-down box to be populated using a result set from a MySQL query.
Yes,
<select name="DynamicField_fieldname">
<!-- code to show options -->
</select>
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
Post Reply