[rt-users] AutoTake for RT3

Craig Schenk murple at murple.net
Tue Mar 23 15:46:11 EST 2004


We're using this to automagically assign tickets to one of the queue's
AdminCc's randomly when tickets get created.

*** Custom action preparation code:

my $retval = undef;

if ( defined( $self->TicketObj->OwnerObj->id ) ){
    if( $self->TicketObj->OwnerObj->Id == $RT::Nobody->Id ) {
        $retval = 1;
    }
}


*** Custom action cleanup code:

my $retval = undef;

my $watchers = $self->TicketObj->QueueObj->AdminCc;
my $accm = $watchers->MembersObj;

my $numWatchers = 0;

# Grab emails of AdminCc objects and shove in array
my @lottery;

while (my $admincc = $accm->Next) {

     # We only want AdminCc's that are users, not groups
     my $email = $admincc->MemberObj->Object->EmailAddress;
     my $isuser = $admincc->MemberObj->IsUser;

     if ($isuser) {
          $numWatchers++;
          push(@lottery, $email);
     }
}

# Pick a lucky watcher
my $winner = $lottery[ int(rand(@lottery)) ];

my $user = new RT::User(RT::SystemUser);
$user->LoadByEmail($winner);
my $id = $user->Id;

# Give the winner a prize
$retval = $self->TicketObj->SetOwner($id);

return($retval);



More information about the rt-users mailing list