[Rt-devel] Ticket Ownership Enumeration Problem

Jeff Albert jralbert at uvic.ca
Tue Jan 11 01:53:01 EST 2005


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 ca

-----Original Message-----
From: Jesse Vincent [mailto:jesse at bestpractical.com] 
Sent: Monday, January 10, 2005 9:28 PM
To: Jeff Albert
Cc: rt-devel at 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 at lists.bestpractical.com
> http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-devel
> 

-- 




More information about the Rt-devel mailing list