AddCustomFieldValue to child ticket created via scrip?

I have a scrip that uses the Action: Create Tickets. When the child ticket is created I need to populate some custom fields using data from the parent.

Fetching the data from the parent ticket is no problem but I cannot figure out how to AddCustomFieldValue to the child ticket.

Would anyone care to give me some clues?

Are you running the scrip on the child ticket? As in $self->TicketObj is the child? I’d think adding the value would just work

I’m not running the scrip on the child ticket.

-Ticket in Queue-A is created or modified.
-A scrip configured with a User Defined Condition checks the values of a few fields. If the correct conditions exist, the condition ‘returns 1’ and the Action: Create Tickets is triggered, using a specific Template.
-Template sets the Subject and Body of the Child Ticket.

I’ve tried using the Template to populate fields but it appears Templates can only fetch/display data, they cannot modify Custom Fields. Somebody please correct me if I’m wrong about that.

So far all I can think to do is stop using the built-in Create Tickets Action and instead write a custom Action that creates the child, grabs the child ticket ID, then modifies the field.

       CustomField-<id#> => custom field value
       CF-name           => custom field value
       CustomField-name  => custom field value

Do one of those styles work in the template?

Trying to add anything like this to the template prevents the child ticket from being created. So far I’m not seeing any errors in the log.

{$self->TicketObj->AddCustomFieldValue( Field => ‘username’, Value => “victory”)}

I think I’ll try creating the child ticket manually so I can get its id and modify it that way. I haven’t found any examples of someone using AddCustomFieldValue in a Template which makes me think it isn’t actually possible.

Can you share the template code? You don’t need this right?

{$self->TicketObj->AddCustomFieldValue( Field => ‘username’, Value => “username”)}

You can have:
CF-username => username

Sure, here’s my working template. Any attempts to add perl that modifies customfields prevents the child ticket from being created at all.

===Create-Ticket: allocations
Subject: {$Tickets{'TOP'}->FirstCustomFieldValue('equipment needed')} for new employee - {$Tickets{'TOP'}->FirstCustomFieldValue('Full Name')}
Parents: TOP
Queue: test2
UpdateType: comment
Content: 
{$Tickets{'TOP'}->DueObj->AsString}
{$Tickets{'TOP'}->Transactions->First->Content}
ENDOFCONTENT

Problem solved. I stopped using the built-in Create Tickets action and wrote my own.

my $childQueue = "allocations";

# Create the child ticket & establish the link
my $parent = $self->TicketObj;
my $child_ticket = RT::Ticket->new(RT->SystemUser);
my ($child_id, $child_TransObj, $errormsg) =
	$child_ticket->Create( 
                   Queue => $childQueue,
			       Subject => $parent->FirstCustomFieldValue('equipment needed').' for new employee - '.$parent->FirstCustomFieldValue('Full Name'),
			       Parents => $parent->Id,
			       Requestor => $parent->RequestorAddresses,
			       Cc => $parent->CcAddresses,
			     );


$child_ticket->Load($child_id);
$child_ticket->AddCustomFieldValue( Field => 'Scheduled Pickup Date', Value => $parent->Due );
$child_ticket->Comment( Content => $parent->Transactions->First->Content );