Hello,<br><br>(sorry about the long posting, I tried to put all the info in)<br><br>I have set up a custom field and scrip that creates a child ticket <br>when the custom field "RolloutOnFTN" is changed to "createchildticket".
<br>The child tickets inherits all custom fields from the parent ticket, but the <br>"RolloutOnFTN" field is set to "pendingchildticket". All this works fine.<br><br>But I also want to update the custom field of the parent ticket to
<br>"pendingchildticket" when the child ticket is created.<br>How can I do that?<br><br>I tried this (borrowing heavily form the workflow example of the wiki):<br><br>=================== begin of scrip =============================
<br>Custom Condition: <br>---------------------------<br># do nothing unless:<br># customfield id3 is changed or created<br># customfield RolloutOnFTN (=id3) is PendingChildTicket<br>my $CFName = 'RolloutOnFTN';<br>
my $CFid = 3;<br>my $CFvalue = 'PendingChildTicket';<br>unless (<br> ( $self->TransactionObj->Type eq "CustomField"<br> && $self->TransactionObj->Field == $CFid )<br> || $self->TransactionObj->Type eq "Create"
<br> ) {<br> return 0;<br>}<br>return 0 unless $self->TicketObj->FirstCustomFieldValue( $CFName ) =~ /$CFvalue/i;<br>1;<br><br>Custom Action Cleanup code:<br>-------------------------------------------<br>### for debugging ####
<br>my $ticket = $self->TicketObj;<br>$ticket->AddCustomFieldValue( Field => 'ReleasePhase' , Value => "01_Proposal" );<br>$self->TicketObj->SetPriority( 100 );<br>$self->TicketObj->SetStatus( "stalled" );
<br><br>#### the real thing ######<br>my $cf_value = 'PendingChildTicket';<br>my $cf_name;<br>### Figure out which kind of child this is<br>my $subject = $self->TicketObj->Subject;<br>$cf_name = 'RolloutOnFTN' if $subject =~ /^ImplementOnFTN/;
<br>$cf_name = 'RolloutOnFTS' if $subject =~ /^ImplementOnFTS/;<br># Repeat for your custom field names.<br># There may be a better way to do this.<br>return undef unless $cf_name;<br>my $actor = $self->TransactionObj->CreatorObj;
<br>my $actorname = $actor->RealName . ' (' . $actor->EmailAddress . ')';<br>my $CF_Obj = RT::CustomField->new($self->CurrentUser);<br>#### current ticket is member of(child of some parents)<br>
my $MemberOf = $self->TicketObj->MemberOf;<br>#### the following only runs if ticket is child of one or more parent:<br>while (my $l = $MemberOf->Next ) {<br> # we can't check non local objects<br> next unless( $l->TargetURI->IsLocal );
<br> # Update the custom field in the parent ticket to show completed.<br> $CF_Obj->LoadByName( Name => $cf_name, <br> Queue => $l->TargetObj->QueueObj->Id);<br> $CF_Obj->AddValueForObject( Object => $l->TargetObj,
<br> Content => $cf_value );<br><br> my $id = $self->TicketObj->id;<br> my $status = $self->TicketObj->Status; <br> $l->TargetObj->Correspond(Content => <<END);<br>
<br> Child ticket created:<br> Ticket: $id <br> Status: $status<br> Subject: $subject<br> By: $actorname<br> END<br>}<br>return 1;<br>================== end of scrip ===============================================
<br><br>When I create the child ticket from the parent then it runs the debug code <br>in the scrip (see below), but it doesn't update the parent ticket. <br>(Btw. The ticket status change is rolled back for some reason, see last line)
<br><br># Thu Oct 25 14:56:03 2007 RT_System - Ticket created [Reply] [Comment] <br>Download (untitled) [text/plain 73b] <br>Implementation on FTN required<br>Please see the parent ticket for details.
<br># Thu Oct 25 14:56:03 2007 RT_System - Outgoing email recorded [Show] <br># Thu Oct 25 14:56:03 2007 RT_System - Status changed from 'open' to 'stalled'
<br># Thu Oct 25 14:56:04 2007 RT_System - ReleasePhase 05_Implementing changed to 01_Proposal <br># Thu Oct 25 14:56:04 2007 RT_System - Priority changed from '60' to '100'
<br># Thu Oct 25 14:56:04 2007 RT_System - Status changed from 'stalled' to 'open' <br> <br>When I trigger this scrip, after the child ticket is created by changing the custom field value to
<br>"pendingchildticket" manually, the scrip runs all the way through and the parent ticket is updated and<br>receives the correspondence.<br><br>Why does it only work in the second case? Any ideas?<br><br>Doro<br>
<br>