Dynamic Field in ticket search [SOLVED]

Moderator: crythias

Locked
rvaldomir
Znuny expert
Posts: 155
Joined: 04 Aug 2014, 23:59
Znuny Version: 3.3.8
Real Name: Roberto A. Valdomir

Dynamic Field in ticket search [SOLVED]

Post by rvaldomir »

Hi I need some help!

I'm trying to create a search for a widget without luck.

I found in the API documentation that Dynamic Field can be used in search: https://otrs.github.io/doc/api/otrs/3.3 ... ch.pm.html

Code: Select all

  # DynamicFields
        #   At least one operator must be specified. Operators will be connected with AND,
        #       values in an operator with OR.
        #   You can also pass more than one argument to an operator: ['value1', 'value2']
        DynamicField_FieldNameX => {
            Equals            => 123,
            Like              => 'value*',                # "equals" operator with wildcard support
            GreaterThan       => '2001-01-01 01:01:01',
            GreaterThanEquals => '2001-01-01 01:01:01',
            SmallerThan       => '2002-02-02 02:02:02',
            SmallerThanEquals => '2002-02-02 02:02:02',
        }
here is my code in the search to get my tickets in stateType=new and TicketEnvironment=PROD, the problem is on the dynamicfield I tested replacing this by

Code: Select all

PriorityIDs => '[1]',
and works.

Code: Select all

my $ProdTicketsOpen = $Self->{TicketObject}->TicketSearch(
        # result (required)
        Result => 'COUNT',

        StateType    => ['new'],
        DynamicField_TicketEnvironment {
               Equals => ['PROD'],
           }
        #PriorityIDs => [1],
        # user search (UserID is required)
        UserID     => 1,
        Permission => 'ro' || 'rw',

        # customer search (CustomerUserID is required)
        CustomerUserID => $Self->{UserID},
        Permission     => 'ro',

        );
Untitled.png
You do not have the required permissions to view the files attached to this post.
Last edited by rvaldomir on 08 Jul 2015, 15:30, edited 1 time in total.
​Roberto A. Valdomir
Mobile: (+598) 93 868 147 | Skype: roberto.a.valdomir
@roberto.valdomir | re.vu/robertovaldomir

----------------------------------------------------------------------------------------
OTRS 3.3.8 | RHEL 6 x64 | Oracle 11g | Custom Development by OTRS365
aph
Znuny superhero
Posts: 646
Joined: 20 Jun 2014, 12:11
Znuny Version: 3.3.9, 4.x, 5.x

Re: Dynamic Field in ticket search

Post by aph »

If I see it right there is a => missing.

Code: Select all

StateType    => ['new'],
        DynamicField_TicketEnvironment => {
               Equals => ['PROD'],
           }
As shown in API

Code: Select all

 # DynamicFields
        #   At least one operator must be specified. Operators will be connected with AND,
        #       values in an operator with OR.
        #   You can also pass more than one argument to an operator: ['value1', 'value2']
        DynamicField_FieldNameX => {
            Equals            => 123,
            .....
            }
OTRS 3.3.x (private/testing) on Windows Server 2008 with MSSQL database.
OTRS 3.3.x (private/testing) on CentOS with MySQL database and apache
rvaldomir
Znuny expert
Posts: 155
Joined: 04 Aug 2014, 23:59
Znuny Version: 3.3.8
Real Name: Roberto A. Valdomir

Re: Dynamic Field in ticket search

Post by rvaldomir »

Code: Select all

# --
# Kernel/Output/HTML/DashboardUserOnline.pm
# Copyright (C) 2001-2014 xxx, http://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --

package Kernel::Output::HTML::TicketOverviewWidget6;

use strict;
use warnings;
use Data::Dumper;
use Kernel::System::State;
use Kernel::System::DynamicField;
use Kernel::System::DynamicField::Backend;


sub new {
    my ( $Type, %Param ) = @_;

    # allocate new hash for object
    my $Self = {%Param};
    bless( $Self, $Type );

    # get needed objects
    for my $Object (
        qw(
        Config Name ConfigObject LogObject DBObject LayoutObject ParamObject TicketObject
        QueueObject UserID
        )
        )
    {
        die "Got no $Object!" if ( !$Self->{$Object} );
    }


    return $Self;
}

sub Preferences {
    my ( $Self, %Param ) = @_;

    return;
}

sub Config {
    my ( $Self, %Param ) = @_;

    return (
        %{ $Self->{Config} },

        # remember, do not allow to use page cache
        # (it's not working because of internal filter)

    );
}

sub Run {
    my ( $Self, %Param ) = @_;

    my $ProdTicketsOpen = $Self->{TicketObject}->TicketSearch(
        # result (required)
        Result => 'COUNT',

        StateType    => ['open'],
        DynamicField_TicketEnvironment => {
               Equals => PROD,
           }

        # user search (UserID is required)
        UserID     => 1,
        Permission => 'ro' || 'rw',

        # customer search (CustomerUserID is required)
        CustomerUserID => $Self->{UserID},
        Permission     => 'ro',

        );
    my $ProdTicketsClosed = $Self->{TicketObject}->TicketSearch(
        # result (required)
        Result => 'COUNT',

        StateType    => ['closed'],
        DynamicField_TicketEnvironment => {
               Like => PROD,
           }

        # user search (UserID is required)
        UserID     => 1,
        Permission => 'ro' || 'rw',

        # customer search (CustomerUserID is required)
        CustomerUserID => $Self->{UserID},
        Permission     => 'ro',

        );
#log
#$Self->{LogObject}->Log(
#Priority => 'info',
#Message  => "content=".Dumper($ProdTicketsOpen, $ProdTicketsClosed),
#);
#
    my $Content = $Self->{LayoutObject}->Output(
        TemplateFile => 'CustomerTicketOverviewWidget6',

        Data         => {
            ProdTicketsOpen => $ProdTicketsOpen,
            ProdTicketsClosed => $ProdTicketsClosed,
        },

    );
#log
$Self->{LogObject}->Log(
Priority => 'info',
Message  => "content=".Dumper($Content),
);
#
    return $Content;
}

1;
Still getting the errors:

Code: Select all

==> /var/log/httpd/error_log <==
[Mon Jul  6 22:30:59 2015] ZZZAAuto.pm: Subroutine Load redefined at /opt/otrs/Kernel/Config/Files/ZZZAAuto.pm line 7.
[Mon Jul  6 22:30:59 2015] ZZZAuto.pm: Subroutine Load redefined at /opt/otrs/Kernel/Config/Files/ZZZAuto.pm line 7.
[Mon Jul  6 22:31:00 2015] TicketOverviewWidget6.pm: Subroutine new redefined at /opt/otrs//Kernel/Output/HTML/TicketOverviewWidget6.pm line 20.
[Mon Jul  6 22:31:00 2015] TicketOverviewWidget6.pm: Subroutine Preferences redefined at /opt/otrs//Kernel/Output/HTML/TicketOverviewWidget6.pm line 42.
[Mon Jul  6 22:31:00 2015] TicketOverviewWidget6.pm: Subroutine Config redefined at /opt/otrs//Kernel/Output/HTML/TicketOverviewWidget6.pm line 48.

==> /tmp/otrs.log.2015-7 <==
[Mon Jul  6 22:31:00 2015][Error][Kernel::Modules::CustomerTicketWidgets::_Element][1365] syntax error at /opt/otrs//Kernel/Output/HTML/TicketOverviewWidget6.pm line 73, near "UserID"
Global symbol "$Self" requires explicit package name at /opt/otrs//Kernel/Output/HTML/TicketOverviewWidget6.pm line 81.
syntax error at /opt/otrs//Kernel/Output/HTML/TicketOverviewWidget6.pm line 91, near "UserID"
Global symbol "$Self" requires explicit package name at /opt/otrs//Kernel/Output/HTML/TicketOverviewWidget6.pm line 95.
Global symbol "$Self" requires explicit package name at /opt/otrs//Kernel/Output/HTML/TicketOverviewWidget6.pm line 105.
Global symbol "$ProdTicketsOpen" requires explicit package name at /opt/otrs//Kernel/Output/HTML/TicketOverviewWidget6.pm line 109.
Global symbol "$Self" requires explicit package name at /opt/otrs//Kernel/Output/HTML/TicketOverviewWidget6.pm line 115.
syntax error at /opt/otrs//Kernel/Output/HTML/TicketOverviewWidget6.pm line 121, near "}"


==> /var/log/httpd/error_log <==
ERROR: OTRS-CGI-90 Perl: 5.10.1 OS: linux Time: Mon Jul  6 22:31:00 2015

 Message: syntax error at /opt/otrs//Kernel/Output/HTML/TicketOverviewWidget6.pm line 73, near "UserID"
Global symbol "$Self" requires explicit package name at /opt/otrs//Kernel/Output/HTML/TicketOverviewWidget6.pm line 81.
syntax error at /opt/otrs//Kernel/Output/HTML/TicketOverviewWidget6.pm line 91, near "UserID"
Global symbol "$Self" requires explicit package name at /opt/otrs//Kernel/Output/HTML/TicketOverviewWidget6.pm line 95.
Global symbol "$Self" requires explicit package name at /opt/otrs//Kernel/Output/HTML/TicketOverviewWidget6.pm line 105.
Global symbol "$ProdTicketsOpen" requires explicit package name at /opt/otrs//Kernel/Output/HTML/TicketOverviewWidget6.pm line 109.
Global symbol "$Self" requires explicit package name at /opt/otrs//Kernel/Output/HTML/TicketOverviewWidget6.pm line 115.
syntax error at /opt/otrs//Kernel/Output/HTML/TicketOverviewWidget6.pm line 121, near "}"


 RemoteAddress: 192.168.7.6
 RequestURI: /otrs/customer.pl?Action=CustomerTicketWidgets;Subaction=MyTickets

 Traceback (31337):
   Module: Kernel::Modules::CustomerTicketWidgets::_Element (OTRS 3.3.8) Line: 1365
   Module: Kernel::Modules::CustomerTicketWidgets::Run (OTRS 3.3.8) Line: 560
   Module: Kernel::System::Web::InterfaceCustomer::Run (OTRS 3.3.8) Line: 1002
   Module: ModPerl::ROOT::ModPerl::Registry::opt_otrs_bin_cgi_2dbin_customer_2epl::handler (unknown version) Line: 41
   Module: (eval) (v1.99) Line: 204
   Module: ModPerl::RegistryCooker::run (v1.99) Line: 204
   Module: ModPerl::RegistryCooker::default_handler (v1.99) Line: 170
   Module: ModPerl::Registry::handler (v1.99) Line: 31

[Mon Jul  6 22:31:00 2015] TicketOverviewWidget6.pm: Subroutine new redefined at /opt/otrs//Kernel/Output/HTML/TicketOverviewWidget6.pm line 20.
[Mon Jul  6 22:31:00 2015] TicketOverviewWidget6.pm: Subroutine Preferences redefined at /opt/otrs//Kernel/Output/HTML/TicketOverviewWidget6.pm line 42.
[Mon Jul  6 22:31:00 2015] TicketOverviewWidget6.pm: Subroutine Config redefined at /opt/otrs//Kernel/Output/HTML/TicketOverviewWidget6.pm line 48.
[Mon Jul 06 22:31:00 2015] [error] [client 192.168.7.6] syntax error at /opt/otrs//Kernel/Output/HTML/TicketOverviewWidget6.pm line 73, near "UserID"\nGlobal symbol "$Self" requires explicit package name at /opt/otrs//Kernel/Output/HTML/TicketOverviewWidget6.pm line 81.\nsyntax error at /opt/otrs//Kernel/Output/HTML/TicketOverviewWidget6.pm line 91, near "UserID"\nGlobal symbol "$Self" requires explicit package name at /opt/otrs//Kernel/Output/HTML/TicketOverviewWidget6.pm line 95.\nGlobal symbol "$Self" requires explicit package name at /opt/otrs//Kernel/Output/HTML/TicketOverviewWidget6.pm line 105.\nGlobal symbol "$ProdTicketsOpen" requires explicit package name at /opt/otrs//Kernel/Output/HTML/TicketOverviewWidget6.pm line 109.\nGlobal symbol "$Self" requires explicit package name at /opt/otrs//Kernel/Output/HTML/TicketOverviewWidget6.pm line 115.\nsyntax error at /opt/otrs//Kernel/Output/HTML/TicketOverviewWidget6.pm line 121, near "}"\nCompilation failed in require at /opt/otrs/Kernel/cpan-lib/Apache2/Reload.pm line 179.\n, referer: http://172.16.1.31/otrs/customer.pl?Action=CustomerTicketWidgets;Subaction=MyTickets
​Roberto A. Valdomir
Mobile: (+598) 93 868 147 | Skype: roberto.a.valdomir
@roberto.valdomir | re.vu/robertovaldomir

----------------------------------------------------------------------------------------
OTRS 3.3.8 | RHEL 6 x64 | Oracle 11g | Custom Development by OTRS365
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Dynamic Field in ticket search

Post by crythias »

What, exactly are you attempting?
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
rvaldomir
Znuny expert
Posts: 155
Joined: 04 Aug 2014, 23:59
Znuny Version: 3.3.8
Real Name: Roberto A. Valdomir

Re: Dynamic Field in ticket search

Post by rvaldomir »

to create a graph the dtl is working, but i need to resolve the "query" to obtain the data

amount of tickets by environment, which is a dynamic field.
​Roberto A. Valdomir
Mobile: (+598) 93 868 147 | Skype: roberto.a.valdomir
@roberto.valdomir | re.vu/robertovaldomir

----------------------------------------------------------------------------------------
OTRS 3.3.8 | RHEL 6 x64 | Oracle 11g | Custom Development by OTRS365
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Dynamic Field in ticket search

Post by crythias »

> Message: syntax error at /opt/otrs//Kernel/Output/HTML/TicketOverviewWidget6.pm line 73, near "UserID"
Missing comma:

Code: Select all

        DynamicField_TicketEnvironment => {
               Equals => PROD,
           },
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
rvaldomir
Znuny expert
Posts: 155
Joined: 04 Aug 2014, 23:59
Znuny Version: 3.3.8
Real Name: Roberto A. Valdomir

Re: Dynamic Field in ticket search

Post by rvaldomir »

yes was that, thanks for you reply,

the documentation is missing that comma :S
​Roberto A. Valdomir
Mobile: (+598) 93 868 147 | Skype: roberto.a.valdomir
@roberto.valdomir | re.vu/robertovaldomir

----------------------------------------------------------------------------------------
OTRS 3.3.8 | RHEL 6 x64 | Oracle 11g | Custom Development by OTRS365
Locked