Change Queue Custom Scrip - moves back to original queue after webui reloads

Greetings Everyone,

I have created a custom status that I am trying to set a condition on to
move tickets from one queue to another. The code that I have used is…

Condition: On Status Change
Action: User Defined

Custom Condition: return 1;
Custom action preparation code: return 1;
Custom action cleanup code:
my $TargetQueueName = ‘Queue2’;
my $NewStatus = ‘PassToQueue2’;
if (($self->TicketObj->Status eq “$NewStatus”) &&
($self->TicketObj->QueueObj->Name ne “$TargetQueueName”)) {
my $TicketObj = $self->TicketObj;
my $Id = $TicketObj->Id;
my $Status = $TicketObj->Status;
my $QueueName = $TicketObj->QueueObj->Name;

if ($Status ne $NewStatus) {
my ($tstatus, $tmsg) = $TicketObj->SetStatus("$NewStatus");
$RT::Logger->info(“Changing status of ticket #”. $Id ." to “. $NewStatus);
unless ($tstatus) {
die “Error: $tmsg”;
if ($QueueName ne $TargetQueueName) {
my ($qstatus, $qmsg) = $TicketObj->SetQueue(”$TargetQueueName");
$RT::Logger->info(“Moving Ticket #”. $Id ." to ". $TargetQueueName .“
unless ($qstatus) {
die “Error: $qmsg”;
return 1;

The ticket moves queues but when the web ui reloads it resets it back to the
old queue.

I appreciate all feedback …