How to get ResponsibleID and declare them right

English! place to talk about development, programming and coding
Post Reply
Nuri
Znuny newbie
Posts: 3
Joined: 13 May 2019, 14:37
Znuny Version: 5.0.30
Real Name: Nurullah Koca

How to get ResponsibleID and declare them right

Post by Nuri »

Hi OTRS community,

I am editing the AgentTicketZoom.pm to add a extra condition.
I want to add the condition if the User is the responsible to do stuff.

I tried this

Code: Select all

    # get ticket object
    my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');

    ###START-TEST-SECTION###
    my %Ticket = $TicketObject->TicketGet(
        TicketID => $TicketID,
        UserID   => 1,
        );

    if(!($Self->{UserID} eq $Ticket->{ResponsibleID})){
        return $LayoutObject->NoPermission( WithHeader => 'No');
    }
The error message is every time the same mostly it is the "not declared" problem.

I googled the entire web for all possibilities. But they all don't work.
Variables like:

Code: Select all

 $Self->(TicketID), $Self->(UserID), $Param->(TicketID)
and more ... are given in the script - but they are not usable in my case :(
I also tried the methods in the OTRS API but it all only works with static values - like static UserID and TicketID.

What do you guys think about the script above?
does anyone know a way to do that without errors?
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: How to get ResponsibleID and declare them right

Post by RStraub »

Well... what is the error message?
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
Nuri
Znuny newbie
Posts: 3
Joined: 13 May 2019, 14:37
Znuny Version: 5.0.30
Real Name: Nurullah Koca

Re: How to get ResponsibleID and declare them right

Post by Nuri »

Ok i find out that everything above

Code: Select all

if(!($Self->{UserID} eq $Ticket->{ResponsibleID})){
        return $LayoutObject->NoPermission( WithHeader => 'No');
    }
was unnecessary and the only problem was that you have to Access Ticket-Attributes without "->".
So only

Code: Select all

$Self->{UserID} and $Ticket{ResponsibleID} 
is usable.
The reason is simple but hard for me to explain, so if someone is interested just search for the "->" syntax in Perl.

The problem was always a decleration error e.g. $Self{UserID} (Wrong wise) is not declared or $Ticket->{ResponsibleID} (Also wrong wise) is not declared or available and stuff.
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: How to get ResponsibleID and declare them right

Post by RStraub »

Oh, you tried to access a Hash with the syntax used for Hash-Refs.

For the future, this the syntax for references in Perl:

Array: my $Array = ... || [];
Hash: my $Hash = ... || {};

And the dereferenced objects are:
Array: my @Array = ... || ();
Hash: my %Hash = ... || ();

To access values for references you use the "->" syntax:
my $Value = $Hash->{Key};
and for a nomal hash:
my $Value = $Hash{Key};
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
Post Reply