Generic Agent Custom module

English! place to talk about OTRS development, programming and coding
Post Reply
lis9
OTRS newbie
Posts: 9
Joined: 13 Apr 2017, 11:27
OTRS Version?: 6.0.15
Real Name: Daniel
Company: Komputronik S.A.

Generic Agent Custom module

Post by lis9 » 15 Jul 2019, 11:06

Hello!

My use case is: when Target ticket is closed -> find parent ticket and change it's dynamic field.
To achieve this I decided to write a custom module (my first module ever!). Module works as designed: takes TicketID passed by Generic Agent, searches for parent and changes parent's DF to desired value, but everytime ends with httpd 500 error and such log:

[Mon Jul 15 10:45:56.468909 2019] [perl:error] [pid 2837] [client 10.21.32.7:37434] Attempt to reload
/opt/otrs//Custom/Kernel/Modules/MyModule.pm aborted.\nCompilation failed in require at /opt/otrs/Kernel/cpan-lib/Apache2/Reload.pm line 179.\n, referer: https://my-url/otrs/index.pl?Action=Adm ... o3lLmQXKSJ;

A source of MyModule.pm is:

Code: Select all

package Custom::Kernel::Modules::MyModule;

use strict;
use warnings;

our @ObjectDependencies = (
    'Kernel::System::LinkObject',
    'Kernel::System::Log',
    'Kernel::System::Ticket',
    'Kernel::GenericInterface::Operation',
    'Kernel::GenericInterface::Debug',
);

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

        my $Self = {};
        bless( $Self, $Type );

        return $Self;
}

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

my $TicketID = $Param{TicketID};
my $parentID = $Param{TicketID};
my $UserID = ($Param{UserID})? $Param{UserID} : 1 ;

#my $LogObject = $Kernel::OM->Get('Kernel::System::Log');
#	$LogObject->{LogPrefix} = 'MyModule';
#	$LogObject->Log( Priority => 'error', Message => "TicketID=$TicketID" );
#	$LogObject->Log( Priority => 'error', Message => "UserID=$UserID" );

my $Links = $Kernel::OM->Get('Kernel::System::LinkObject')->LinkList(
        Object => 'Ticket',
        Key    => $TicketID,
        State  => 'Valid',
        Type   => 'ParentChild',
        Direction => 'Source',
        UserID => $UserID,
    );
#$LogObject->Log( Priority => 'error', Message => $Links );

    return 1 if !$Links;
    return 1 if ref $Links ne 'HASH';
    return 1 if !$Links->{Ticket};
    return 1 if ref $Links->{Ticket} ne 'HASH';
    return 1 if !$Links->{Ticket}->{ParentChild};
    return 1 if ref $Links->{Ticket}->{ParentChild} ne 'HASH';
    return 1 if !$Links->{Ticket}->{ParentChild}->{Source};
    return 1 if ref $Links->{Ticket}->{ParentChild}->{Source} ne 'HASH';

#$LogObject->Log( Priority => 'error', Message => 'Przed petla');

 my $OpenSubTickets = 0;
    TICKETID:
    for my $TicketID ( sort keys %{ $Links->{Ticket}->{ParentChild}->{Source} } ) {

        # get ticket
        my %Ticket = $Kernel::OM->Get('Kernel::System::Ticket')->TicketGet(
           TicketID	 => $TicketID,
           DynamicFields => 0,
        );
	if ( $Ticket{StateType} !~ m{ \A (close|merge|remove) }xms ) {
             $OpenSubTickets = 1;
             $parentID = $Ticket{TicketID};
             last TICKETID;
        }
    }

#$LogObject->Log( Priority => 'error', Message => "Parent=$parentID" );
#$LogObject->Log( Priority => 'error', Message => "Ticketow nadrzednych: $OpenSubTickets");

if ( !$OpenSubTickets ) { return; };

my %Parent = $Kernel::OM->Get('Kernel::System::Ticket')->TicketGet(
        TicketID => $parentID,
        DynamicFields => 1,
        );

#$LogObject->Log( Priority => 'error', Message => "Parent TN = $Parent{TicketNumber}" );
#$LogObject->Log( Priority => 'error', Message => "Parent DF Dzial = $Parent{DynamicField_dzial}" );


my $DebuggerObject = Kernel::GenericInterface::Debugger->new(
        DebuggerConfig   => {
            DebugThreshold => 'debug',
            TestMode	   => 0,
        },
	WebserviceID	  => 9,
        CommunicationType => 'Provider',
    );

my $updateObj = Kernel::GenericInterface::Operation->new(
        DebuggerObject => $DebuggerObject,
        Operation      => 'TicketUpdate',
        OperationType  => 'Ticket::TicketUpdate',
        WebserviceID   => 9,
);
my $Update = $updateObj->Run(
        Data => {
                UserLogin => 'some_login',
                Password => 'password',
                TicketID => $Parent{TicketID},
                DynamicField => [ { Name => 'dzial', Value => 'po updejcie' }, ],
        },
   );


return 1;
}

1;
Any idea whats wrong? :(

skullz
OTRS wizard
Posts: 180
Joined: 24 Feb 2012, 03:58
OTRS Version?: OTRS 6

Re: Generic Agent Custom module

Post by skullz » 18 Jul 2019, 08:11

Restart htppd..try again..see the log

Post Reply