Difference between revisions of "AutoSetOwnerFromCC"

From Request Tracker Wiki
Jump to navigation Jump to search
m (2 revisions imported)
m
 
Line 5: Line 5:
 
Description: [[AutoAssign]] Owner From Cc Condition: On Create Action: User Defined Template: Global Template: Blank Stage: [[TransactionCreate]]
 
Description: [[AutoAssign]] Owner From Cc Condition: On Create Action: User Defined Template: Global Template: Blank Stage: [[TransactionCreate]]
  
/Custom Condition:/
+
=== Custom Condition ===
  
 
  return 1;
 
  return 1;
 
   
 
   
  
/Custom Action Preparation:/
+
=== Custom Action Preparation ===
  
 
  return 1;
 
  return 1;
 
   
 
   
 +
=== Custom Action Cleanup Code ===
  
/Custom Action Cleanup Code:/
+
<pre>
 
+
  # Get the first CC
  <nowiki># Get the first CC
 
 
  my $newowner = $self-&gt;TicketObj-&gt;Cc-&gt;UserMembersObj-&gt;Next;
 
  my $newowner = $self-&gt;TicketObj-&gt;Cc-&gt;UserMembersObj-&gt;Next;
 
   
 
   
Line 46: Line 46:
 
   
 
   
 
  return 1;
 
  return 1;
  </nowiki>
+
  </pre>

Latest revision as of 20:09, 13 August 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.

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;