From Request Tracker Wiki
Jump to navigation Jump to search

Here is some basic Perl code for creating a batch of tickets using the CLI interface to RT. To get the proper numbers for the custom values fields use the 'View Source' option when looking at a ticket in the appropriate queue. This is just a quick script, but it should give enough pointers to get you started on creating tickets.

  1. !/usr/bin/perl -w
use RT::Interface::CLI;
use RT;
use RT::Ticket;
use RT::CurrentUser;
my $CurrentUser = RT::Interface::CLI::GetCurrentUser();

use MIME::Entity;

$LEASE = "/home/dawsons/rt/leasedata";  # each line gives info on a ticket to create

open(LEASE, "<$LEASE") || die "Couldn't open $LEASE: $!";

while (<LEASE>)
  ($subject, $dept, $replacement, $body, $j) = split(/\t/, $_, 5);
  print STDERR "Have extra data '$j'\n" if $j;
  my $ticket = new RT::Ticket($CurrentUser);
  my $ticket_body = MIME::Entity->build(Data => $body,
                                       Type => 'text/plain');
  my %ticket_vals = ( Queue => 'Lease',
                      Subject => $subject,
                      Owner => 'root',
                      Requestor => '',
                      InitialPriority => '11',
                      FinalPriority => '20',
                      MIMEObj => $ticket_body,
                      'CustomField-5' => $dept,
                      'CustomField-14' => $replacement
  my ($id, $transaction_object, $err) = $ticket->Create(%ticket_vals);
  print STDERR $err . "\n" if $err;