RT3 : Automatically assign owner by queue

There is one bit of functionality that I keep reusing for pretty much every installation of RT3 – automatic assignment of tickets to specific users based on queue.  There are a few solutions to this problem and some are documented in RT3 wiki.  But I always keep forgetting which solution to use and where I found it.  So, in hopes not to ever spend more than 3 seconds searching for such a solution, I’m posting it here.

We’ll be using a global scrip instead of a per-queue scrip.  This will simplify maintenance for those installations that use a lot of queues – you’ll need to change settings only in one place rather than all over the place.  Create the new global scrip with the following settings:

  • Description: AutoSetOwnerForQueue
  • Condition: On Create
  • Action: User Defined
  • Template: Global Template : Blank
  • Stage: TransactionCreate
  • Custom condition: return 1;
  • Custom action preparation code: return 1;
  • Custom action cleanup code:
my %owners = (
  'queue_name1' => 'username1',
  'queue_name2' => 'username1',
  'queue_name3' => 'username2',
);
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;

Last time I’ve used this was on RT 3.8.8. Adjust accordingly for the earlier and later versions.