Help with Scrip for child / dependent tickets

Hi there,

We are wanting to have a scrip run on our queues which will move a ticket back to the “open” state if all of its child and dependent tickets are closed (resolved, rejected or deleted).

I have found Ruslan’s scrip which opens a ticket once all of its child tickets are closed here on the wiki: http://requesttracker.wikia.com/wiki/OpenTicketOnAllMemberResolve which works great. However we have tried to edit this to work on depending / dependent tickets but cannot get it working. Here is the scrip, can anyone see what we are missing?

end if setting this ticket to “resolved, deleted or rejected”

return 1 if ($self->TransactionObj->NewValue !~ /^(?:resolved|deleted|rejected)$/);

current ticket is a dependant of (Depended on by some parents)

my $DependedOnBy = $self->TicketObj->DependedOnBy;
while( my $l = $DependedOnBy->Next ) {
# we can’t check non local objects
next unless( $l->TargetURI->IsLocal );
# if dependant ticket is not in active state then scrip can skip it
next unless( $l->TargetObj->Status =~ /^(?:new|open|stalled|pending|planning|holiday)$/ );

# the dependant ticket has dependencies (current ticket is one of them)
my $ds = $l->TargetObj->DependsOn();

my $flag = 0;
while( my $d = $ds->Next ) {
  next unless( $d->BaseURI->IsLocal );
  next unless( $d->BaseObj->Status =~ /^(?:new|open|stalled|pending|planning|holiday)$/ );
  $flag = 1;
  last;
}
# shouldn't open dependant if some dependency is active
next if( $flag );
# All dependent tickets closed - open depending ticket
$l->TargetObj->SetStatus('open');

}

return 1;

Once we can get this scrip working we would ideally like a single scrip which will check all tickets on status change to see if it has a parent or depending ticket; and then if all child or dependent tickets for its parent are closed, to reopen the parent…

Any help greatly received!

Jon

Jon Witts
Director of Digital Strategy
Queen Margaret’s School
Escrick Park
York YO19 6EU

Telephone: 01904 727600
Fax: 01904 728150

Website: www.queenmargarets.com

This email has been processed by Smoothwall Anti-Spam - www.smoothwall.net

Hi Jon,

I had a similar requirement I suppose. I had an original (Parent) ticket
and this ticket has two dependent tickets at a certain stage before
proceeding down the rest of the workflow. I achieved this requirement by
having a scrip running when the dependent tickets are completed to check
whether the other dependent is closed and if it is then to progress the
parent ticket status. I think effectively it is probably the same general
thing you are trying to do.

This is the custom action from my scrip.

my $CurrentUser =
RT::CurrentUser->new( $self->TransactionObj->Creator );

Put actions in scope of our user

my $Ticket =
new RT::Ticket($CurrentUser);# New ticket object
$Ticket
->load( $self->TicketObj->id );
my $MemberOf =
$self->TicketObj->DependedOnBy; # Find the Parent Ticket Identifier.
my $Link = $MemberOf->Next; # Get the Link for Parent
Object.
my $Parent = new RT::Ticket($CurrentUser); # New Parent ticket object
$Parent->load( $Link->BaseObj->id );
my $Queue = $Parent->QueueObj;

my $children = new RT::Tickets( $CurrentUser );
$children->LimitDependedOnBy ($Parent->id);

my $complete = 0;

while (my $child = $children->Next){
if ($child->Status eq ‘Completed’){
$complete = $complete + 1;
}
}

if ( $complete == 2 ) {
# Both tickets are completed so we can progress
$Parent->SetStatus(‘In Progress-Allocate Resources’);
$Parent->Comment( ‘Content’ => ‘Design/Consent phase completed’);
}

Regards,

AaronOn Sat, May 9, 2015 at 2:03 AM Jon Witts jwitts@queenmargarets.com wrote:

Hi there,

We are wanting to have a scrip run on our queues which will move a ticket
back to the “open” state if all of its child and dependent tickets are
closed (resolved, rejected or deleted).

I have found Ruslan’s scrip which opens a ticket once all of its child
tickets are closed here on the wiki:
http://requesttracker.wikia.com/wiki/OpenTicketOnAllMemberResolve which
works great. However we have tried to edit this to work on depending /
dependent tickets but cannot get it working. Here is the scrip, can anyone
see what we are missing?


end if setting this ticket to “resolved, deleted or rejected”

return 1 if ($self->TransactionObj->NewValue !~
/^(?:resolved|deleted|rejected)$/);

current ticket is a dependant of (Depended on by some parents)

my $DependedOnBy = $self->TicketObj->DependedOnBy;
while( my $l = $DependedOnBy->Next ) {
# we can’t check non local objects
next unless( $l->TargetURI->IsLocal );
# if dependant ticket is not in active state then scrip can skip it
next unless( $l->TargetObj->Status =~
/^(?:new|open|stalled|pending|planning|holiday)$/ );

# the dependant ticket has dependencies (current ticket is one of them)
my $ds = $l->TargetObj->DependsOn();

my $flag = 0;
while( my $d = $ds->Next ) {
  next unless( $d->BaseURI->IsLocal );
  next unless( $d->BaseObj->Status =~

/^(?:new|open|stalled|pending|planning|holiday)$/ );
$flag = 1;
last;
}
# shouldn’t open dependant if some dependency is active
next if( $flag );
# All dependent tickets closed - open depending ticket
$l->TargetObj->SetStatus(‘open’);
}

return 1;


Once we can get this scrip working we would ideally like a single scrip
which will check all tickets on status change to see if it has a parent or
depending ticket; and then if all child or dependent tickets for its parent
are closed, to reopen the parent…

Any help greatly received!

Jon


Jon Witts
Director of Digital Strategy
Queen Margaret’s School
Escrick Park
York YO19 6EU

Telephone: 01904 727600
Fax: 01904 728150

Website: www.queenmargarets.com

This email has been processed by Smoothwall Anti-Spam - www.smoothwall.net

Hi Aaron,

Thanks for sharing your scrip. I think your scrip is similar but not quite what I was wanting to do. Yours seems hardcoded to only check for two child tickets. I would like my scrip to loop through all child tickets and change the status of the parent if all child tickets are resolved…

Does anyone have any pointers? I can’t see where this is falling down.

Thanks,
Jon

Jon Witts
Director of Digital Strategy
Queen Margaret’s School
Escrick Park
York YO19 6EU

Telephone: 01904 727600
Fax: 01904 728150

Website: www.queenmargarets.comhttp://www.queenmargarets.com/From: Aaron Guise [mailto:aaron@guise.net.nz]
Sent: 18 May 2015 00:55
To: Jon Witts; rt-users@lists.bestpractical.com
Subject: Re: [rt-users] Help with Scrip for child / dependent tickets

Hi Jon,
I had a similar requirement I suppose. I had an original (Parent) ticket and this ticket has two dependent tickets at a certain stage before proceeding down the rest of the workflow. I achieved this requirement by having a scrip running when the dependent tickets are completed to check whether the other dependent is closed and if it is then to progress the parent ticket status. I think effectively it is probably the same general thing you are trying to do.

This is the custom action from my scrip.

my $CurrentUser =
RT::CurrentUser->new( $self->TransactionObj->Creator );

Put actions in scope of our user

my $Ticket =
new RT::Ticket($CurrentUser);# New ticket object
$Ticket
->load( $self->TicketObj->id );
my $MemberOf =
$self->TicketObj->DependedOnBy; # Find the Parent Ticket Identifier.
my $Link = $MemberOf->Next; # Get the Link for Parent Object.
my $Parent = new RT::Ticket($CurrentUser); # New Parent ticket object
$Parent->load( $Link->BaseObj->id );
my $Queue = $Parent->QueueObj;

my $children = new RT::Tickets( $CurrentUser );
$children->LimitDependedOnBy ($Parent->id);

my $complete = 0;

while (my $child = $children->Next){
if ($child->Status eq ‘Completed’){
$complete = $complete + 1;
}
}

if ( $complete == 2 ) {
# Both tickets are completed so we can progress
$Parent->SetStatus(‘In Progress-Allocate Resources’);
$Parent->Comment( ‘Content’ => ‘Design/Consent phase completed’);
}

Regards,
Aaron

Hi,

this is what we use:

my $deps = $self->TicketObj->DependedOnBy;
while( my $link = $deps->Next ) {
next unless $link->BaseURI->IsLocal;
my $dep = $link->BaseObj;
next if $dep->QueueObj->IsInactiveStatus($dep->Status);
$dep->SetStatus(‘open’) unless $dep->HasUnresolvedDependencies;
}

ChrisAm 22.05.2015 um 11:35 schrieb Jon Witts:

Hi Aaron,

Thanks for sharing your scrip. I think your scrip is similar but not
quite what I was wanting to do. Yours seems hardcoded to only check for
two child tickets. I would like my scrip to loop through all child
tickets and change the status of the parent if all child tickets are
resolved…

Does anyone have any pointers? I can’t see where this is falling down.

Thanks,
Jon

Hi Chris,

Thanks for the pointer; I will update the scrip accordingly.

Thanks,
Jon

Jon Witts
Director of Digital Strategy
Queen Margaret’s School
Escrick Park
York YO19 6EU

Telephone: 01904 727600
Fax: 01904 728150

Website: www.queenmargarets.comFrom: Christian Loos [mailto:cloos@netcologne.de]
Sent: 22 May 2015 13:38
To: Jon Witts
Subject: Re: Help with Scrip for child / dependent tickets

Hi,

next unless( $l->BaseObj->Status =~
/^(?:new|open|stalled|pending|planning|holiday)$/ );
Actually this line uses a hard coded list of statuses.
Once you change the lifecycle for a queue, this maybe won’t work any more. So it is better to use the IsInactiveStatus or IsActiveStatus methods on a queue object, which respects lifecycle changes.

Chris