Updating "ResetPriorityAndDueDate" for 4.4.2 compatibility

I’ve tried using a code from the wiki https://rt-wiki.bestpractical.com/wiki/OnQueueChangeResetPriorityAndDueDate but it was not working… until I realized some Queue’s methods had been removed from 4.2.4 to 4.4.2 as mentioned in https://docs.bestpractical.com/rt/4.4.2/UPGRADING-4.4.html

the version is not mentioned in the wiki article, and as I don’t have an account there i couldn’t modify it.

So i updated the code to be compatible with 4.4.2 using the new methods (and with a different personalized condition), here’s the commit code :slight_smile:

my $queue = $self->TicketObj->QueueObj;

 # Reset Priority
 unless ( $self->TicketObj->Priority == $queue->DefaultValue('InitialPriority') ) {
   $RT::Logger->info("[Scrip #69] set ticket #". $self->TicketObj->id ." priority to ". $queue->DefaultValue('InitialPriority') );
   my ( $status, $msg ) = $self->TicketObj->SetPriority( $queue->DefaultValue('InitialPriority') );
   unless ( $status ) {
 $RT::Logger->error( "[Scrip #69] Unable to assign priority to ". $queue->DefaultValue('InitialPriority') );
 $RT::Logger->error( "[Scrip #69] Message: $msg" );
   }
 }
 # Reset Final Priority
 unless ( $self->TicketObj->FinalPriority == $queue->DefaultValue('FinalPriority') ) {
   $RT::Logger->info("[Scrip #69] set ticket #". $self->TicketObj->id ." final priority to ". $queue->DefaultValue('FinalPriority') );
   my ( $status, $msg ) = $self->TicketObj->SetFinalPriority( $queue->DefaultValue('FinalPriority') );
   unless ( $status ) {
 $RT::Logger->error( "[Scrip #69] Unable to assign final priority to ". $queue->DefaultValue('FinalPriority') );
 $RT::Logger->error( "[Scrip #69] Message: $msg" );
   }
 }  

 # Reset Due Date
 my $due_date = RT::Date->new( $RT::SystemUser );
 $due_date->Set( Format => 'ISO', Value => $self->TicketObj->Due );
 
 # If queue doesn't specify due date, add 4 weeks
 # Otherwise, add that many days.

 if ( $queue->DefaultValue('Due') == 0 ) {
   $due_date->SetToNow;
   $due_date->AddDays( 28 );
   # or we could clear the due date
   #$due_date->Set( Format => 'ISO', Value => 0 );
 } else {
   $due_date->SetToNow;
   $due_date->AddDays( $queue->DefaultValue('Due') );
 }
 
 $RT::Logger->info("[Scrip #69] set ticket #". $self->TicketObj->id ." due date to ". $due_date->ISO );

 # Apply to ticket
 my ( $status, $msg ) = $self->TicketObj->SetDue( $due_date->ISO );

 unless ( $status ) {
   $RT::Logger->error( "[Scrip #69] Unable to assign due date to ". $due_date->ISO );
 }

return 1;