Check for queue name on all DependedOnBy Tickets

Hi There,

I have a script to check if a ticket has DependedOnBy tickets, and if it has, I want to get the queue name for that ticket and check if it’s a specific queue name. I’ve created the script below, but it’s not working properly and I don’t know what I’m doing wrong. It stops after the first loop, and only check the queue for the current ticket

PS: If I use the same script to check for a parent ticket (MemberOf), it’s working fine. If I create a child ticket from a parent ticket. But If I create a DependsOn ticket, it will not work anymore.

e.g my $DependedOnBy = $ticket->MemberOf;

my $txn = $self->TransactionObj;
my $type = $txn->Type;

return 0 unless $type eq "Status";

$RT::Logger -> info("SCRIP #77 CHECk IF DependedOnBy Q IS Q_Name");

my $ticket = $self->TicketObj;
my $DependedOnBy = $ticket-> DependedOnBy;

return 0 unless $DependedOnBy;

while( my $dependedOnBy = $DependedOnBy->Next )
{   

    my $dependedOnByQueueName = $dependedOnBy->TargetObj->QueueObj->Name;

    $RT::Logger -> info("SCRIPT #77 CHECK FOR DependedOnBy -- ${dependedOnByQueueName}");

    if($dependedOnByQueueName eq "Q_Name") {
        $RT::Logger->info("SCRIP #77 - QUEUE IS ${dependedOnByQueueName}");
        return 1;
    }

    $RT::Logger -> info("SCRIP #77 - There is no DependedOnBy ticket in Q Q_Name");

}

$RT::Logger -> info("END OF SCRIP #77 CHECk IF DependedOnBy Q IS Q_Name");
return 0;

UPDATE - SOLUTION:

Change the TargetObj my $dependedOnByQueueName = $dependedOnBy->TargetObj->QueueObj->Name;. with BaseObj my $dependedOnByQueueName = $dependedOnBy->BaseObj->QueueObj->Name;

Does it find a queue name matching Q_Name on the first loop and then stop?

No it doesn’t find that matching Q_Name ( thats the issue ) . It find the Q_Name for the “child ticket” and stops after that.

A concrete exemple:

I have the “parent ticket” that is on queue “A” and a “child” ticket that is on queue “B” . The scrip on fist iterations, check for queue name “B” and then it stops and exit the while loop

If :

my $dependedOnByQueueName = $dependedOnBy->TargetObj->QueueObj->Name;

returns “Q_Name” the scrip will bail. Which it sounds like “It find the Q_Name for the “child ticket” and stops after that.” thats what is happening right?

Yeah, that’s what is happening

Yeah, that’s what is happening

And then the scrip runs? It sounds like the scrip is doing what you’d expect no?

What I need is to get to this part of the script. To find The Q_Name for the “parent” ticket, not the “child” ticket, but right now, my script only checks for the Q_Name of the “child” ticket.

If you’re looking to check the DependsOn ticket then you can just check the $self->TicketObj right

In other words, I need a method that will return all the DependsOn tickets for one ticket. And after that, I want to check if one of that DependOn ticket, is from a specific queue

I could be confused but:

my $ticket = $self->TicketObj;
my $DependedOnBy = $ticket-> DependedOnBy;

Here you get all the tickets that depend on the ticket that is kicking off the scrip.

while( my $dependedOnBy = $DependedOnBy->Next )

Then you loop over those tickets, but here you check the target of the link:

my $dependedOnByQueueName = $dependedOnBy->TargetObj->QueueObj->Name;

Which I assume would be your original $self->TicketObj you started with. I think what you want is this:

my $dependedOnByQueueName = $dependedOnBy->BaseObj->QueueObj->Name;

But I could be confused about Target vs Base, best to just add a ton of debug and see what ticket you’re actually getting the queue name from

The solution was the BaseObj :sunglasses:

I’ve changed the TargetObj with BaseObj and the loop checks for the right Q name

Thanks for the help

1 Like