AutoSetOwnerFromCC: Difference between revisions

From Request Tracker Wiki
Jump to navigation Jump to search
m (2 revisions imported)
(No difference)

Revision as of 15:03, 6 April 2016

This is a variation on AutoSetOwner, it auto-sets the owner of a ticket by using the Cc watcher. It then removes the new owner from the Cc.

  1. Condition: On Create # Action: User Defined # Template: blank # Stage: TransactionCreate

Description: AutoAssign Owner From Cc 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:/

# Get the first CC
 my $newowner = $self->TicketObj->Cc->UserMembersObj->Next;
 
 if (defined $newowner) {
   $RT::Logger->debug("Attempting to auto assign ticket #". $self->TicketObj->id ." to user #". $newowner->id);
 
   my ($status, $msg) = $self->TicketObj->SetOwner( $newowner );
   unless( $status ) {
     $RT::Logger->error( "Impossible to assign ticket #" . $self->TicketObj->id . " to user #" . $newowner->id . ": $msg" );
     return undef;
   }
 
   $RT::Logger->debug("Auto-assign successful for ticket #". $self->TicketObj->id);
 
   # Now we need to remove them as Cc
   $RT::Logger->debug("Attempting to remove user #" . $newowner->id . " as Cc on ticket #". $self->TicketObj->id);
 
   my ($status, $msg)= $self->TicketObj->DeleteWatcher(
                                                      Type => "Cc",
                                                      PrincipalId => $newowner->id);
   unless( $status ) {
     $RT::Logger->error( "Unable to remove user #" . $newowner->id . " as Cc for ticket #" . $self->TicketObj->id);
     return undef;
   }
 
   $RT::Logger->debug("Cc removal successful for ticket #". $self->TicketObj->id);
 }
 
 return 1;