Reputation: 1137
I'm using invoker TestSimple.pm of trigger 'ArticleCreate'. (Ideally should've created a new invoker!) I'm able to receive the json data of the ticket correctly via REST web service. I want an additional ticket attribute with this-> 'ticket body'. How can i modify the invoker (perl file) so that it also sends ticket body in the json data? Or is their any other trigger that can give me this out-of-the-box? I went through OTRS manual and getting confused again-n-again :( So, if someone can give me proper link that will also do!
System details: 1. OTRS v4.0 2. Apache web server
[Edit] Added the TestSimple.pm file. This is the link I referred.
#copyright (C) 2001-2014 OTRS AG, 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::GenericInterface::Invoker::Test::TestSimple;
use strict;
use warnings;
use Kernel::System::VariableCheck qw(IsString IsStringWithData);
use Kernel::System::Ticket;
our $ObjectManagerDisabled = 1;
=head1 NAME
Kernel::GenericInterface::Invoker::Test::Test - GenericInterface test Invoker backend
=head1 SYNOPSIS
=head1 PUBLIC INTERFACE
=over 4
=cut
=item new()
usually, you want to create an instance of this
by using Kernel::GenericInterface::Invoker->new();
=cut
sub new {
my ( $Type, %Param ) = @_;
# allocate new hash for object
my $Self = {};
bless( $Self, $Type );
# check needed params
if ( !$Param{DebuggerObject} ) {
return {
Success => 0,
ErrorMessage => "Got no DebuggerObject!"
};
}
$Self->{DebuggerObject} = $Param{DebuggerObject};
$Self->{TicketObject} = Kernel::System::Ticket->new(%Param);
return $Self;
}
=item PrepareRequest()
prepare the invocation of the configured remote webservice.
This will just return the data that was passed to the function.
my $Result = $InvokerObject->PrepareRequest(
Data => { # data payload
...
},
);
my %Article = $TicketObject->ArticleGet(
ArticleID => $Param{Data}->{ArticleID},
UserID => $Param{Data}->{CustomerID},
);
$Result = {
Success => 1, # 0 or 1
ErrorMessage => '', # in case of error
Data => { # data payload after Invoker
...
},
};
=cut
sub PrepareRequest {
my ( $Self, %Param ) = @_;
my %TicketInfo = $Self->{TicketObject}->ArticleGet(
ArticleID => $Param{Data}->{ArticleID},
userID => $Param{Data}->{CustomerID},
);
return {
Success => 1,
Data => $TicketInfo{Body},
};
}
=item HandleResponse()
handle response data of the configured remote webservice.
This will just return the data that was passed to the function.
my $Result = $InvokerObject->HandleResponse(
#my $Result = $TicketBodyObject->HandleResponse(
ResponseSuccess => 1, # success status of the remote webservice
ResponseErrorMessage => '', # in case of webservice error
Data => { # data payload
...
},
);
$Result = {
Success => 1, # 0 or 1
ErrorMessage => '', # in case of error
Data => { # data payload after Invoker
%Article
},
};
=cut
sub HandleResponse {
my ( $Self, %Param ) = @_;
# if there was an error in the response, forward it
if ( !$Param{ResponseSuccess} ) {
return {
Success => 0,
ErrorMessage => $Param{ResponseErrorMessage},
};
}
return {
Success => 1,
Data => $Param{Data},
};
}
1;
=back
=head1 TERMS AND CONDITIONS
This software is part of the OTRS project (L<http://otrs.org/>).
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 L<http://www.gnu.org/licenses/agpl.txt>.
=cut
Upvotes: 0
Views: 610
Reputation: 4294
PrepareRequest only knows about the TicketID
and ArticleID
it is operating on.
You'll need to look up the data you need to pass in the PrepareRequest()
sub of your Invoker, and then return it in the Data parameter.
Check the code below for an example how to add the article body:
sub PrepareRequest {
my ( $Self, %Param ) = @_;
my %Article = $Kernel::OM->Get('Kernel::System::Ticket')->ArticleGet(
ArticleID => $Param{Data}{ArticleID},
UserID => 1,
);
return {
Success => 1,
Data => {
TicketID => $Param{Data}{TicketID},
ArticleID => $Param{Data}{ArticleID},
Body => $Article{Body},
},
};
}
Upvotes: 1