Ticket Ownership Enumeration Problem

Hello all,
I’m a beginner at hacking RT, and at Perl, so please forgive me if this
turns out to be a foolish question, but:

I’m trying to create a scrip which will, upon ticket creation, evaluate a
custom field value to determine which group of our team should address the
issue, then determine who among them has the fewest open tickets, and
finally choose a random member of that subset to be assigned ownership of
the ticket. Presently I’m stuck at trying to determine how many tickets a
given user has open. It seems to me that this should be fairly trivial, but
I’m having no luck. Here’s what I’m doing currently:

#…$org is gotten from custom field…

if ($org eq ‘HUMA’) {
my %HSD = (‘jralbert’ => 0, ‘jafraser’=> 0, ‘mhelfric’ => 0);
my $CurrentUser = $RT::SystemUser;
my $OpenTickets;
$OpenTickets = new RT::Tickets ($CurrentUser);
while ($id, $score) = each(%HSD)) {
$MyTickets->UnLimit();
$MyTickets->LimitOwner( VALUE => “jralbert” );
$MyTickets->LimitStatus( VALUE=> “open” );
$HSD{$id} = $MyTickets->Count();
}
}

It looks as if the scrip dies on trying the LimitOwner method, and gets no
further. What am I doing wrong? I thank you in advance for any help you may
provide.

Cheers,
Jeff Albert

Departmental Computing Support Team
University of Victoria
British Columbia, Canada
jralbert at uvic dot ca

#…$org is gotten from custom field…

if ($org eq ‘HUMA’) {
my %HSD = (‘jralbert’ => 0, ‘jafraser’=> 0, ‘mhelfric’ => 0);
my $CurrentUser = $RT::SystemUser;
my $OpenTickets;
$OpenTickets = new RT::Tickets ($CurrentUser);

# This line serves no purpose

while ($id, $score) = each(%HSD)) {

	# There's no MyTickets object
  $MyTickets->UnLimit();
	# Rather than do this, why don't you do:

my	$MyTickets = RT::Tickets->new($RT::SystemUser);
  $MyTickets->LimitOwner( VALUE => "jralbert" );
  $MyTickets->LimitStatus( VALUE=> "open" );
  $HSD{$id} = $MyTickets->Count();

}
}

Once you have this all worked up, please document it on the wiki.

Jesse

Yes, the code was an error-riddled mess. Sorry about that! I really
shouldn’t post while halfway through altering my code. Here’s the revised,
and now-working version:

#org is gotten from custom field…

if ($org eq ‘HUMA’) {

#define team and vars...

my %HSD = ('jralbert' => 0, 'jafraser'=> 0, 'mhelfric' => 0);
my $CurrentUser = $RT::SystemUser;
my $id;
my $score;

#now, let's find out how many tickets everyone has.

while (($id, $score) = each(%HSD)) {
	my $OpenTickets = new RT::Tickets ($CurrentUser);
	$OpenTickets->LimitOwner( VALUE => $id );
	$OpenTickets->LimitQueue( VALUE => 'COUS_DCST_Test' );
	$OpenTickets->LimitStatus ( VALUE => 'open' );
	$HSD{$id} = $OpenTickets->Count();
	$report .= ' ' . $id . ' : ' . $HSD{$id};
}

#next, let's set a threshold value absurdly high,
#then whittle it down to the lowest number of tickets any user has

open.

my $topscore = 999;
while (($id, $score) = each(%HSD)) {
	if ($score < $topscore) {
		$topscore = $score;
	}
}

#finally, let's get subset of our team who have that number of

tickets open…

my @candidates;
while (($id, $score) = each(%HSD)) {
	if ($score == $topscore){
		push(@candidates, $id);
	}
}

#...and pick one of them randomly to be assigned the task.

my $final = $candidates[int rand scalar @candidates];
$self->TicketObj->SetOwner($final);

}

If this code is useful to anyone, they’re welcome to it! Thanks for the
feedback and help!

Cheers,
Jeff Albert
Departmental Computing Support Team
University of Victoria
British Columbia, Canada
jralbert at uvic dot caFrom: Jesse Vincent [mailto:jesse@bestpractical.com]
Sent: Monday, January 10, 2005 9:28 PM
To: Jeff Albert
Cc: rt-devel@lists.bestpractical.com
Subject: Re: [Rt-devel] Ticket Ownership Enumeration Problem

#…$org is gotten from custom field…

if ($org eq ‘HUMA’) {
my %HSD = (‘jralbert’ => 0, ‘jafraser’=> 0, ‘mhelfric’ => 0);
my $CurrentUser = $RT::SystemUser;
my $OpenTickets;
$OpenTickets = new RT::Tickets ($CurrentUser);

# This line serves no purpose

while ($id, $score) = each(%HSD)) {

	# There's no MyTickets object
  $MyTickets->UnLimit();
	# Rather than do this, why don't you do:

my	$MyTickets = RT::Tickets->new($RT::SystemUser);
  $MyTickets->LimitOwner( VALUE => "jralbert" );
  $MyTickets->LimitStatus( VALUE=> "open" );
  $HSD{$id} = $MyTickets->Count();

}
}

Once you have this all worked up, please document it on the wiki.

Jesse

It looks as if the scrip dies on trying the LimitOwner method, and gets no
further. What am I doing wrong? I thank you in advance for any help you
may
provide.

Cheers,
Jeff Albert

Departmental Computing Support Team
University of Victoria
British Columbia, Canada
jralbert at uvic dot ca


Rt-devel mailing list
Rt-devel@lists.bestpractical.com
http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-devel