AutoSetOwnerForQueue

From Request Tracker Wiki
Revision as of 15:54, 7 January 2011 by 99.224.22.98 (talk) (Cleaned up Wiki formatting)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Say you want all the requests for new hardware to go to the queue "hardware" and be assigned to Joe the hardware guy. If so, this page is for you.

The procedure involves 3 actions:

1. Creating the queue "hardware"

2. Adding the following email alias

hardware: |/usr/local/rt3/bin/rt-mailgate --queue hardware --action correspond --url http://rt.yoursite.com/

3. Creating this Global scrip

Description: Assign Hardware Requests to Joe
Condition: On Create
Action: User Defined
Template: Global Template: Blank
Stage: TransactionCreate

Custom Condition:

return 1;

Custom Action Preparation:

return 1;

Custom Action Cleanup Code:

my %owners = ( 'hardware' => 'joe',); 
my $QueueName = $self->TicketObj->QueueObj->Name; 
return 1 unless defined($owners{$QueueName}); 
my $Actor = $self->TransactionObj->Creator; 
return 1 if $Actor == $RT::SystemUser->id; 
return 1 unless $self->TicketObj->Owner == $RT::Nobody->id; 
my $MyUser = $owners{$QueueName}; 
$RT::Logger->info("Auto assigning ticket #". $self->TicketObj->id ." to user $MyUser" ); 
my ($status, $msg) = $self->TicketObj->SetOwner( $MyUser ); 
unless( $status ) {
      $RT::Logger->warning( "Impossible to assign the ticket to $MyUser: $msg" );
return undef; 

} 1;

And that's it. Now you can send an email to hardware@yoursite.com and a ticket will be automatically created in the queue hardware and assigned to Joe. Thanks Joe, now come fix my !@##$# mouse!

And if you have more queues that you want to automatically set owners at, just add the pairs queue=>owner to the %owners hash.

Assigning owner conditionally based on ticket creator

Let's say you want to automatically set the owner, but only if you're looking for something specific in the ticket creator's email address. The example below is if you want to automatically assign tickets to "harry" if (a) they are sent from anyone@domain1.com or anyone@domain2.com, and (b) to the "general" queue.

Alternate Custom Action Cleanup Code:

my $MyUser = "harry";
my $QueueName = "general";
my $Sender = "@(domain1|domain2)\.com";
return 1 unless $self->TicketObj->QueueObj->Name eq $QueueName;
my $Actor = $self->TransactionObj->Creator;
return 1 if $Actor == $RT::SystemUser->id;
return 1 unless $self->TicketObj->Owner == $RT::Nobody->id;
return 1 unless $self->TransactionObj->CreatorObj->Name() =~ /$Sender/;
$RT::Logger->info("Auto assigning ticket #". $self->TicketObj->id ." to user $MyUser" );
my ($status, $msg) = $self->TicketObj->SetOwner( $MyUser );
unless( $status ) {
  $RT::Logger->warning("Impossible to assign the ticket to $MyUser: $msg");
  return undef;
}
1;

Changelog

20060501 Haim Dimer.

20060506 Andrew Foster - added alternate custom action code for conditional requestor

Comments

2006.01.05 purp@acm.org: Seems like, with a little tweaking of how $MyUser is assigned, you could round-robin through the members of an RT group. I don't know how you'd preserve the state of who was last assigned, but that's the only hitch I see.

2006.04.12 jcolson@voidgate.org: How about querying the number of tickets assigned to each person in the group and assigning to the person with the least open.