[rt-users] Scrip to resolve parent when all children resolved

Emmanuel Lacour elacour at easter-eggs.com
Wed Jun 23 04:18:29 EDT 2010


On Tue, Jun 22, 2010 at 01:08:26PM -0700, Jonathan Rummel wrote:
> 
> I have a scrip in place that creates 4 child tickets in queue B upon creation
> of a ticket (the parent) in queue A.  Is there a way for the parent to check
> the status of the child tickets and automatically resolve itself when the
> last of the child tickets is resolved?
> 

I use a scrip with condition OnResolve that close parents if they have all
children (except the current one) resolved. Here is the action:

    # Loop on each relation type (Depends, Refers, Member)
    foreach my $type ( keys %{$self->TicketObj->LINKDIRMAP} ) {
        my $target = $self->TicketObj->LINKDIRMAP->{$type}->{Target};
        my $base = $self->TicketObj->LINKDIRMAP->{$type}->{Base};
        # Skip merges
        next if ( $target =~ /merge/i );

        # Loop on parents
        while ( my $Parent = $self->TicketObj->$target->Next ) {
            # Only for tickets links
            next unless ( $Parent->BaseObj && $Parent->BaseObj->isa('RT::Ticket') );
            my $ParentTicket = $Parent->BaseObj;
            # Only for unresolved parents
            next if ( $ParentTicket->Status eq 'resolved' );
            my $to_be_resolved = 1;

            # Loop on Childrens
            while ( my $Child = $ParentTicket->$base->Next ) {
                # Only for tickets links
                next unless ( $Child->TargetObj && $Child->TargetObj->isa('RT::Ticket') );
                my $ChildTicket = $Child->TargetObj;
                # Current ticket doesn't matters
                next if ( $ChildTicket->Id == $self->TicketObj->Id );
                # Stop if unresolved child found
                if ( $ChildTicket->Status ne 'resolved' ) {
                    $to_be_resolved = 0;
                    last;
                }
            }
            if ( $to_be_resolved ) {
                $ParentTicket->SetStatus('resolved');
            }
        }
    }

    return (1);




More information about the rt-users mailing list