This is what I use. It does everything, creates tickets, does
parent-child relationships, and fills in some custom fields. You’d have
to change the custom fields and library locations to suit your
installation (or just don’t use those options). I find this easier to
use than the rt CLI which has limited options.
#!/usr/bin/perl -w
use lib (“/opt/rt3/local/lib”,“/opt/rt3/lib”);
use RT::Interface::CLI;
use RT;
use RT::Ticket;
use RT::CurrentUser;
use Getopt::Long;
$queue = ‘’;
$body = ‘’;
GetOptions (“queue=s” => $queue,
“subject=s” => $subject,
“owner=s” => $owner,
“requestor=s” => $requestor,
“priority=s” => $priority,
“body=s” => $body,
“AdminCc=s” => $AdminCc,
“cc=s” => $cc,
“site=s” => $site,
“work_type=s” => $work_type,
“department=s” => $department,
“group=s” => $group,
“RefersTo=s” => $RefersTo,
“ReferredToBy=s” => $ReferredToBy,
“DependsOn=s” => $DependsOn,
“Parents=s” => $Parents
);
setting some defaults
if ($queue eq ‘’)
{
print_usage();
exit (0);
}
if ($body eq ‘’)
{
$body=’ ';
}
RT::LoadConfig();
RT::Init();
if ($owner eq ‘’) {$owner = ‘Nobody’;}
my $CurrentUser = RT::Interface::CLI::GetCurrentUser();
use MIME::Entity;
my $ticket = new RT::Ticket($CurrentUser);
my $ticket_body = MIME::Entity->build(Data => $body,Type =>
‘text/plain’);
my %ticket_vals = ( Queue => $queue,
Subject => $subject,
Owner => $owner,
Requestor => $requestor,
InitialPriority => $priority,
# FinalPriority => ‘0’,
MIMEObj => $ticket_body,
AdminCc => $AdminCc,
Cc => $cc,
‘CustomField-1’ => $site,
‘CustomField-2’ => $work_type,
‘CustomField-9’ => $department,
‘CustomField-14’ => $group,
‘RefersTo’ => $RefersTo,
‘ReferredToBy’ => $ReferredToBy,
‘DependsOn’ => $DependsOn,
‘MemberOf’ => $Parents
);
my ($id, $transaction_object, $err) = $ticket->Create(%ticket_vals);
print STDERR $err . “\n” if $err;
sub print_usage
{
print “\nusage: rt_custom.pl -queue
Hi Everyone,
Does anyone have a code snippet that depicts the method for linking one
ticket to another using a perl script? It would be even better if the
snippet was part of code that was used to create a new ticket and link
to either existing ticket or a URI.
Take care!
Nick
Nick Metrowsky
Consulting System Administrator
303-684-4785 Office
303-684-4100 Fax
nmetrowsky@digitalglobe.com mailto:nmetrowsky@digitalglobe.com
DigitalGlobe (r), An Imaging and Information Company
http://www.digitalglobe.com http://www.digitalglobe.com