I have written a perl script to log otrs change requests through command line. The script reads a file on local disk which has the description details and uses the same data to update the description field on the change ticket. However, I'm facing an issue with this. Looks like, only the first line read, is being update on the otrs change ticket and the rest of the lines after first line is being ignored by OTRS. Any pointers as what I'm doing wrong?
Below is my piece of code. Kindly note that, I'm reading contents from a file '/home/sindhu/cr1' into an array @lines and providing the same as Description value inside ChangeAdd.
Here is my contents of cr1 with 3 lines in it.
sindhu@supercomp:~$ cat cr1
Test line 1
Test line 2
Test line3
Code: Select all
#!/usr/bin/perl -w
use Getopt::Long;
use Kernel::Config;
use Kernel::System::Encode;
use Kernel::System::Time;
use Kernel::System::Log;
use Kernel::System::DB;
use Kernel::System::Ticket;
use Kernel::System::Main;
use Kernel::System::User;
use Kernel::System::Group;
use Kernel::System::ITSMChange;
my $user;
my $path_to_file='/home/sindhu/cr1';
GetOptions ( "Username=s" => \$user, # string
)
or die("Error in command line arguments\n");
open my $handle, '<', $path_to_file;
(my @lines = <$handle>);
close $handle;
print @lines;
my $ConfigObject = Kernel::Config->new();
my $EncodeObject = Kernel::System::Encode->new(
ConfigObject => $ConfigObject,
);
my $LogObject = Kernel::System::Log->new(
ConfigObject => $ConfigObject,
EncodeObject => $EncodeObject,
);
my $MainObject = Kernel::System::Main->new(
ConfigObject => $ConfigObject,
EncodeObject => $EncodeObject,
LogObject => $LogObject,
);
my $TimeObject = Kernel::System::Time->new(
ConfigObject => $ConfigObject,
LogObject => $LogObject,
);
my $DBObject = Kernel::System::DB->new(
ConfigObject => $ConfigObject,
EncodeObject => $EncodeObject,
LogObject => $LogObject,
MainObject => $MainObject,
);
my $UserObject = Kernel::System::User->new(
ConfigObject => $ConfigObject,
LogObject => $LogObject,
MainObject => $MainObject,
TimeObject => $TimeObject,
DBObject => $DBObject,
EncodeObject => $EncodeObject,
);
my $GroupObject = Kernel::System::Group->new(
ConfigObject => $ConfigObject,
LogObject => $LogObject,
DBObject => $DBObject,
MainObject => $MainObject,
EncodeObject => $EncodeObject,
);
my $ChangeObject = Kernel::System::ITSMChange->new(
ConfigObject => $ConfigObject,
EncodeObject => $EncodeObject,
LogObject => $LogObject,
DBObject => $DBObject,
TimeObject => $TimeObject,
MainObject => $MainObject,
UserObject => $UserObject,
GroupObject => $GroupObject,
);
my %User = $UserObject->GetUserData(
User => $user,
);
my $ChangeID = $ChangeObject->ChangeAdd(
ChangeTitle => 'Test ticket by sindhu - pls ignore', # (optional)
Description => @lines, # (optional)
Justification => 'Change ticket through comd line succeded', # (optional)
# ChangeStateID => 4, # (optional) or ChangeState => 'accepted'
# ChangeState => 'accepted', # (optional) or ChangeStateID => 4
# ChangeManagerID => 5, # (optional)
# ChangeBuilderID => 6, # (optional)
# CategoryID => 7, # (optional) or Category => '3 normal'
# Category => '3 normal', # (optional) or CategoryID => 4
# ImpactID => 8, # (optional) or Impact => '4 high'
# Impact => '4 high', # (optional) or ImpactID => 5
# PriorityID => 9, # (optional) or Priority => '5 very high'
Priority => '3 normal', # (optional) or PriorityID => 6
# CABAgents => [ 1, 2, 4 ], # UserIDs # (optional)
# CABCustomers => [ 'tt', 'mm' ], # CustomerUserIDs # (optional)
# RequestedTime => '2006-01-19 23:59:59', # (optional)
# ChangeFreeKey1 => 'Sun', # (optional) change freekey fields from 1 to ITSMChange::FreeText::MaxNumber
# ChangeFreeText1 => 'Earth', # (optional) change freetext fields from 1 to ITSMChange::FreeText::MaxNumber
UserID => $User{'UserID'},
);
print "Change added. Change ID is $ChangeID";
Additionally, when the file contains even number of lines, I get an error like below. I'm clueless about this error message. Kindly help.
sindhu@supercomp:~/scripts$ cat ~/cr1
Test line 1
Test line 2
sindhu@supercomp:~/scripts$ ./CreateTicket.pl --Username nagabhus
Test line 1
Test line 2
Odd number of elements in hash assignment at /opt/otrs/Kernel/System/ITSMChange.pm line 191.
ERROR: ?LogPrefix?-10 Perl: 5.14.2 OS: linux Time: Wed Dec 25 14:11:55 2013
Message: Need UserID!
Traceback (16146):
Module: Kernel::System::ITSMChange::ChangeAdd (v1.285.2.1) Line: 195
Module: ./CreateTicket.pl (unknown version) Line: 90
Use of uninitialized value $ChangeID in concatenation (.) or string at ./CreateTicket.pl line 113.