Custom Module (Generic Agent Job Management)

Moderator: crythias

Post Reply
steeman
Znuny newbie
Posts: 67
Joined: 22 May 2013, 11:35
Znuny Version: 3.3.2
Real Name: Philip Steeman
Company: VIVES

Custom Module (Generic Agent Job Management)

Post by steeman »

Hello,
is there a tutorial to write a simple Custom Module for OTRS6? I want to call it from Generic Agent Job Management.

I want to change the TicketCustomer of some tickets depending on a info in the body.

Is there only a .pm needed?
Is the directory of the module free to choose? Kernel::Custum::MyFirstModule
Do I need a xml-file for this?


Sorry for my questions but I can't find a good manual for this.

Philip
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: Custom Module (Generic Agent Job Management)

Post by RStraub »

Hey Philip,

this should be easy enough. You can use any path below ~otrs you like, I prefer to keep customizations in ~otrs/Custom.
So let's say you have a module called "Template" in ~otrs/Custom/GAModules/Template.pm
Put there:

Code: Select all

#!/usr/bin/perl

# This module is triggered by a generic agent

package GAModules::Template;

use strict;
use warnings;
use utf8;
use lib '/opt/otrs/';
use lib '/opt/otrs/Kernel/cpan-lib';
use lib '/opt/otrs/Custom';

use Kernel::System::ObjectManager;
local $Kernel::OM = Kernel::System::ObjectManager->new(
    'Kernel::System::Log' => {
        LogPrefix => "MyLogPrefix",
    },
);

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

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

    return $Self;
}

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

    my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
    my $UserObject = $Kernel::OM->Get('Kernel::System::User');
    my %Ticket = $TicketObject->TicketGet(
         TicketID => $Param{TicketID},
         UserID => 1,
         DynamicFields => 1,
    );

    # TODO Put here some if's and elses


    # Update the TicketCustomer
    my $Success = $TicketObject->TicketCustomerSet(
        No       => 'client123',        # Use Number
        User     => 'client-user-123',  # OR customer-user
        TicketID => $Param{TicketID},
        UserID   => 1,                  # 1 for the default root account or maybe $Param{UserID}
    );

    # Return a truthy value (usually the result of your update command)
    return $Success;
}
1;

It's important that the file name does match the declaration. So if you change the filename, also change:

Code: Select all

package GAModules::Template
.

Then, from the webinterface, put at the bottom of the generic agent as "Execute custom module" the module, for this example it would be

Code: Select all

GAModules::Template
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
steeman
Znuny newbie
Posts: 67
Joined: 22 May 2013, 11:35
Znuny Version: 3.3.2
Real Name: Philip Steeman
Company: VIVES

Re: Custom Module (Generic Agent Job Management)

Post by steeman »

This works. Fantastic. Thank you.
Post Reply