Updating parent when child ticket changes - problems

Hello,

(sorry about the long posting, I tried to put all the info in)

I have set up a custom field and scrip that creates a child ticket
when the custom field “RolloutOnFTN” is changed to “createchildticket”.
The child tickets inherits all custom fields from the parent ticket, but the

“RolloutOnFTN” field is set to “pendingchildticket”. All this works fine.

But I also want to update the custom field of the parent ticket to
"pendingchildticket" when the child ticket is created.
How can I do that?

I tried this (borrowing heavily form the workflow example of the wiki):

=================== begin of scrip =============================
Custom Condition:

do nothing unless:

customfield id3 is changed or created

customfield RolloutOnFTN (=id3) is PendingChildTicket

my $CFName = ‘RolloutOnFTN’;
my $CFid = 3;
my $CFvalue = ‘PendingChildTicket’;
unless (
( $self->TransactionObj->Type eq “CustomField”
&& $self->TransactionObj->Field == $CFid )
|| $self->TransactionObj->Type eq “Create”
) {
return 0;
}
return 0 unless $self->TicketObj->FirstCustomFieldValue( $CFName ) =~
/$CFvalue/i;
1;

Custom Action Cleanup code:

for debugging

my $ticket = $self->TicketObj;
$ticket->AddCustomFieldValue( Field => ‘ReleasePhase’ , Value =>
“01_Proposal” );
$self->TicketObj->SetPriority( 100 );
$self->TicketObj->SetStatus( “stalled” );

the real thing

my $cf_value = ‘PendingChildTicket’;
my $cf_name;

Figure out which kind of child this is

my $subject = $self->TicketObj->Subject;
$cf_name = ‘RolloutOnFTN’ if $subject =~ /^ImplementOnFTN/;
$cf_name = ‘RolloutOnFTS’ if $subject =~ /^ImplementOnFTS/;

Repeat for your custom field names.

There may be a better way to do this.

return undef unless $cf_name;
my $actor = $self->TransactionObj->CreatorObj;
my $actorname = $actor->RealName . ’ (’ . $actor->EmailAddress . ‘)’;
my $CF_Obj = RT::CustomField->new($self->CurrentUser);

current ticket is member of(child of some parents)

my $MemberOf = $self->TicketObj->MemberOf;

the following only runs if ticket is child of one or more parent:

while (my $l = $MemberOf->Next ) {
# we can’t check non local objects
next unless( $l->TargetURI->IsLocal );

Update the custom field in the parent ticket to show completed.

$CF_Obj->LoadByName( Name => $cf_name,
Queue => $l->TargetObj->QueueObj->Id);
$CF_Obj->AddValueForObject( Object => $l->TargetObj,
Content => $cf_value );

my $id = $self->TicketObj->id;
my $status = $self->TicketObj->Status;
$l->TargetObj->Correspond(Content => <<END);

Child ticket created:
Ticket: $id
Status: $status
By: $actorname
END
}
return 1;
================== end of scrip

When I create the child ticket from the parent then it runs the debug code
in the scrip (see below), but it doesn’t update the parent ticket.
(Btw. The ticket status change is rolled back for some reason, see last
line)

Thu Oct 25 14:56:03 2007 RT_System - Ticket created

[Reply] [Comment]
Download (untitled) [text/plain 73b]
Implementation on FTN required
Please see the parent ticket for details.

Thu Oct 25 14:56:03 2007 RT_System - Outgoing email recorded

  [Show]

Thu Oct 25 14:56:03 2007 RT_System - Status changed from ‘open’

to ‘stalled’

Thu Oct 25 14:56:04 2007 RT_System - ReleasePhase

05_Implementing changed to 01_Proposal

Thu Oct 25 14:56:04 2007 RT_System - Priority changed from ‘60’

to ‘100’

Thu Oct 25 14:56:04 2007 RT_System - Status changed from

‘stalled’ to ‘open’

When I trigger this scrip, after the child ticket is created by changing the
custom field value to
"pendingchildticket" manually, the scrip runs all the way through and the
parent ticket is updated and
receives the correspondence.

Why does it only work in the second case? Any ideas?

Doro