[rt-users] Creating a Link to a Ticket via a Perl Script
Rappaport, Evan
evan at mtvn.com
Tue Mar 14 11:59:41 EST 2006
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 <rt queue> [optional
parameters]\n";
print "\nThe queue name is manditory but all other
parameters are optional.\n";
print "The following options are supported:\n\n";
print "-subject <subject> \n";
print "-owner <owner> \n";
print "-requestor <requestor e-mail> \n";
print "-priority <Initial Priority> \n";
print "-AdminCc <AdminCc> \n";
print "-cc <Cc> \n";
print "-site <site> \n";
print "-work_type <Work Type> \n";
print "-department <department> \n";
print "-group <Group Performed By>\n";
print "-subject <subject> \n";
print "-body <ticket body> \n";
print "-RefersTo <Refers To> \n";
print "-ReferredToBy <Referred To By> \n";
print "-DependsOn <Depends On>\n";
print "-Parents <Parents>\n";
print "\nExample: ./rt_custom.pl -queue=\"Development\"
-subject=\"This is a test subject for test script\" -owner='bob'
-requestor='bob\@bob.com' -priority=99 -body=\"This is the body of the
ticket\" -AdminCc=\"bobsboss\@bob.com\" -cc=\"bobswife\@bob.com\"
-site=\"secure.bob.com\" -work_type=\"Task\" -department=\"bob business
unit\"\n\n";
}
----------------------------------------------------------------
________________________________
From: rt-users-bounces at lists.bestpractical.com
[mailto:rt-users-bounces at lists.bestpractical.com] On Behalf Of Nick
Metrowsky
Sent: Tuesday, March 14, 2006 11:36 AM
To: rt-users at lists.bestpractical.com
Subject: [rt-users] Creating a Link to a Ticket via a Perl Script
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 at digitalglobe.com <mailto:nmetrowsky at digitalglobe.com>
DigitalGlobe (r), An Imaging and Information Company
http://www.digitalglobe.com <http://www.digitalglobe.com>
------------------------------------------------------------------------
---------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20060314/0a6b3522/attachment.htm>
More information about the rt-users
mailing list