[rt-users] Perl API: list of available queues, owners, status

Richard McMahon rgm at ast.cam.ac.uk
Fri Jul 13 11:42:59 EDT 2012

Ok, I am nearly there. Yes, I have looked the perldoc but got a little
lost. It is very comprehensive but Perl is my third language :).

I am nearly there. I need the list of possible ticket owners. This is the 
list of people in the admin group, maybe.

My previous report scripts used raw sql but I want to rewrite the reports 
using as much of the RT API code bases as possible.

Below I summarise the input on getting the valid status values; note
we have some extra ones and the queuses

my $lifecycle = RT::Lifecycle->Load('default');
my @statuses = $lifecycle->Valid;

for my $status (@statuses) {
     print $status, "\n";

my $queues = RT::Queues->new( RT->SystemUser );
while ( my $queue = $queues->Next ) {
     print $queue->Name, "\n";

So, is there something simialar that list the members who
can own a ticket?


On Fri, 13 Jul 2012, Tim Cutts wrote:

> Date: Fri, 13 Jul 2012 10:01:33 +0100
> From: Tim Cutts <tjrc at sanger.ac.uk>
> To: Richard McMahon <rgm at ast.cam.ac.uk>
> Cc: rt-users at lists.bestpractical.com
> Subject: Re: [rt-users] Perl API: list of available queues, owners, status
> On 13 Jul 2012, at 01:01, Richard McMahon wrote:
>> OK, that gets me the queue list.
>> Is there an API way to get the full list of valid status values
> That's part of the configuration; it's not an API as such.  That information is all configurable by you in the %Lifecycle configuration (look in RT_Config.pm).
> See the documentation for the RT::Lifecycle module:
> my $lifecycle = RT::Lifecycle->Load('default');
> my @statuses = $lifecycle->Valid;
> probably gets you what you want.  Most of the perl classes that the BestPractical guys expect us to use in scripts have reasonable pod documentation, although often you have to remember to also consult the superclass documentation as well, since sometimes the documentation is at that level, in things like RT::Record and RT::SearchBuilder.
>> and also
>> the list of names of ticket owners.
> Well, you can always construct that from any list of tickets that you've previously obtained.  The method is similar to the one mentioned before for iterating over queues; instead, you iterate over the tickets and fetch the name of the owner from each one.  Note that this is likely to be quite slow if there are a lot of tickets.
> You could, of course query the database directly, with something like:
> select distinct(u.Name) from Users u, Tickets t where t.Owner = u.id;
> but querying the database directly is not generally considered a smart thing to do, although I doubt this part of the schema is going to change any time soon.
>> I have looked that the code
>> that Ruslan mentions but I am able see how to get at the owner
>> list and list of valid status values.
> I find that most of the RT code base itself is usually fairly clear (with the exceptions of some of the hairier web interface corners), and when I want to find out how to do something in the RT API I just search the main RT code for places where the same thing is being done, and copy it!
> Regards,
> Tim

  Dr. Richard G. McMahon    | Phone (office)     44-(0)-1223-337519
  University of Cambridge   |       (switchboard)       1223-337548
  Institute of Astronomy    |       (secretary)         1223-337516
  Madingley Rd              | FAX                       1223-337523
  Cambridge, CB3 OHA, UK.   | mobile                    7885-409019
  Office: Hoyle 18          | home                      1223-359770
  email: rgm at ast.cam.ac.uk  | WWW:    http://www.ast.cam.ac.uk/~rgm
  richardgmcmahon at gmail.com | skype:                richardgmcmahon

More information about the rt-users mailing list