Reputation: 237
I´m using an OTRS Ticket System 5 with ITSM. I can select, update, delete Tickets, Attachment over the Generic Interface (REST).
My Problem: The Rest Interface give me only the Ticket data, not the linked Configuration item (for example a pc). I know, i must add a connector for the LinkObject that gives me all the linked items from the Ticket. My Perl programming Skill is not enough to build it on my own, can someone show me how i get a functional solution? After two weeks of searching and trying, i hope someone have solved the problem in the past :)
Here i my perl module that is producing an internal server error (the LinkAdd example is from How to Link / Get Config Item to an Ticket through Webservice (SOAP or REST) in OTRS):
Under /Custom/Kernel/GenericInterface/Operation/LinkObject/LinkList.pm
# --
# Kernel/GenericInterface/Operation/LinkObject/LinkAdd.pm - GenericInterface LinkAdd operation backend
# Copyright (C) 2016 ArtyCo (Artjoms Petrovs), http://artjoms.lv/
# --
# 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::Operation::LinkObject::LinkList;
use strict;
use warnings;
use Kernel::GenericInterface::Operation::Common;
use Kernel::System::LinkObject;
use Kernel::System::VariableCheck qw(IsStringWithData IsHashRefWithData);
=head1 NAME
Kernel::GenericInterface::Operation::LinkObject::LinkList - GenericInterface Link List Operation backend
=head1 SYNOPSIS
=head1 PUBLIC INTERFACE
=over 4
=cut
=item new()
usually, you want to create an instance of this
by using Kernel::GenericInterface::Operation->new();
=cut
sub new {
my ( $Type, %Param ) = @_;
my $Self = {};
bless( $Self, $Type );
# check needed objects
for my $Needed (
qw( DebuggerObject WebserviceID )
)
{
if ( !$Param{$Needed} ) {
return {
Success => 0,
ErrorMessage => "Got no $Needed!"
};
}
$Self->{$Needed} = $Param{$Needed};
}
# create additional objects
$Self->{CommonObject} = Kernel::GenericInterface::Operation::Common->new( %{$Self} );
$Self->{LinkObject}
= $Kernel::OM->Get('Kernel::System::LinkObject');
return $Self;
}
=item Run()
Create a new link.
my $Result = $OperationObject->Run(
Data => {
SourceObject => 'Ticket',
SourceKey => '321',
TargetObject => 'Ticket',
TargetKey => '12345',
Type => 'ParentChild',
State => 'Valid',
UserID => 1,
},
);
$Result = {
Success => 1, # 0 or 1
ErrorMessage => '', # In case of an error
Data => {
Result => 1, # 0 or 1
},
};
=cut
sub Run {
my ( $Self, %Param ) = @_;
# check needed stuff
if ( !IsHashRefWithData( $Param{Data} ) ) {
return $Self->{CommonObject}->ReturnError(
ErrorCode => 'LinkList.MissingParameter',
ErrorMessage => "LinkList: The request is empty!",
);
}
my $LinkID = $Self->{LinkObject}->LinkList(
%Param,
);
if ( !$LinkID ) {
return $Self->{CommonObject}->ReturnError(
ErrorCode => 'LinkList.AuthFail',
ErrorMessage => "LinkList: Authorization failing!",
);
}
return {
Success => 1,
Data => {
Result => $LinkID,
},
};
}
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: 1500
Reputation: 85
Is your problem still active? If it is, please, look out to the link provided: How to Link / Get Config Item to an Ticket through Webservice (SOAP or REST) in OTRS with my comments on the perl module. At least, LinkObject have few methods to implement:
my $LinkList = $LinkObject->LinkList(
Object => 'Ticket',
Key => '321',
Object2 => 'FAQ', # (optional)
State => 'Valid',
Type => 'ParentChild', # (optional)
Direction => 'Target', # (optional) default Both (Source|Target|Both)
UserID => 1,
);
my $LinkList = $LinkObject->LinkListWithData(
Object => 'Ticket',
Key => '321',
Object2 => 'FAQ', # (optional)
State => 'Valid',
Type => 'ParentChild', # (optional)
Direction => 'Target', # (optional) default Both (Source|Target|Both)
UserID => 1,
ObjectParameters => { # (optional) backend specific flags
Ticket => {
IgnoreLinkedTicketStateTypes => 0|1,
},
},
);
and two others returning just keys. I use the LinkListWithData, cause it returns full info about connected CIs.
Also, i have to said that there is some troubles with right creating $Self->{LinkObject} try to use instead of
# create additional objects
$Self->{CommonObject} = Kernel::GenericInterface::Operation::Common->new( %{$Self} );
$Self->{LinkObject} = $Kernel::OM->Get('Kernel::System::LinkObject');
this one
local $Kernel::OM = Kernel::System::ObjectManager->new( %{$Self} );
$Self->{LinkObject} = $Kernel::OM->Get('Kernel::System::LinkObject');
It may helps. When you call LinkList method, you put %Param, but your fields in the Map (or HashMap, dunno exactly in perl) $Param{Data}, so try to use
my $Links = $Self->{LinkObject}->LinkListWithData(
'Object' => $Param{Data}{Object},
'Key' => $Param{Data}{Key},
'Type' => $Param{Data}{Type},
'Object2' => $Param{Data}{Object2},
'State' => $Param{Data}{State},
'UserID' => $Param{Data}{UserID},
);
Also, do not hestitate to make rude debug output like fileappender with Dumper (make shure, that otrs user can create file and write to it):
my $outfile = '/opt/otrs/var/log/otrs.log';
my $timestamp = localtime(time);
open(my $file_handle, '>>', $outfile) or die "Can't write to file '$outfile' [$!]\n";
print $file_handle "$timestamp\n";
print $file_handle "=====Custom LinkList started=====\n";
my $tempobjectdump = Dumper $Self;
print $file_handle $tempobjectdump;
while ( my ($key, $value) = each($Param{Data}) ) {
print $file_handle "$key => $value\n";
}
Upvotes: 0