Scrip to auto change queue status counter

I have a RTIR version 6.0.1 on Ubuntu 22.

I have created a queue named “service desk”and also created a lifecycle named the same with the statuses of new, open, assigned, held, resolved. (All those are active)

I want that when i change the owner of the complaint, the counter should be changed -1 fron the new status and +1 to the assigned status and open status remain the same and when the complaint will be resolved the counter from assigned and open should be -1 and +1 to the resolved status.

I have tried the below scrip but no changes occur in the queue status counter.

my $ticket = $self->TicketObj;

my $old_owner = $self->TicketObj->OldValue;

my $new_owner = $ticket->Owner;

# Agar owner change hua hai (0 = Nobody / Unassigned)

if ($old_owner == 0 || $old_owner == 1) {

\# Agar current status "new" ya "open" hai to "assigned" kar do

if ($ticket->Status eq 'new' || $ticket->Status eq 'open') {

    my ($status_ok, $msg) = $ticket->SetStatus('assigned');

    if (!$status_ok) {

        $RT::Logger->error("Failed to set status to assigned: $msg");

    }

}

}

return 1;