Scrip - How to apply Custom Field Value to a child ticket

Hello,

I am using a “user define” Scrip to create a child ticket on resolve. RT version 5.0.2

Using this forum I managed to overcome most obstacles and now I have a working solution.
When conditions are met a child ticket is created in the right queue,with correct subject, requester, attachments etc.

Unfortunately I am unable to set the custom field value on the child ticket.

I am pasting here the part of child ticket creation from the scrip

    # Create the child ticket & establish the link
my $child_ticket = RT::Ticket->new(RT->SystemUser);
my ($child_id, $child_TransObj, $errormsg) =
	$child_ticket->Create( 
                   Queue => $ticket->Queue,
			       Subject => $ticket->Subject,
			       RefersTo => $ticket->Id,
			       MIMEObj => $MIMEObj,
			       Requestor => $ticket->RequestorAddresses,
			       Cc => $ticket->CcAddresses,
			       AdminCc => $ticket->AdminCcAddresses,
                                   Owner => $ticket->Owner,
			     );

My scrip is mostly based on this post:

Also I can set the custom field value on the parent ticket with this code:

              my( $status, $msg ) = $self->TicketObj->AddCustomFieldValue(
                                    Field => $CFName,
                                    Value => $DefaultCFValue ,
                                    RecordTransaction => 1 );

but don t know how to adjust to apply it to the child ticket.

I am not too proficient in coding but it seems to me I am missing something simple maybe ?
I found in the doco “CustomField- – a scalar or array of values for the customfield with the id ” but I don t know how to use this either

Any hints?

Regards
Filip

I figured it out myself.

# Create the child ticket & establish the link
my $child_ticket = RT::Ticket->new(RT->SystemUser);
my ($child_id, $child_TransObj, $errormsg) =
	$child_ticket->Create( 
                   Queue => $ticket->Queue,
			       Subject => 'Not Resolved: #'. $ticket->Id . ':' . $ticket->Subject,
			       RefersTo => $ticket->Id,
			       MIMEObj => $MIMEObj,
			       Requestor => $ticket->RequestorAddresses,
			       Cc => $ticket->CcAddresses,
			       AdminCc => $ticket->AdminCcAddresses,
                  'CustomField-24' => $CF_TT,
			     );

Not exactly sure why but custom filed has to be in quotes ’ ’
‘CustomField-24’ => $CF_TT works for me.

Hope it helps someone!
Cheers.

Once you’ve created the child ticket you should also be able to call the AddCustomFieldValue() method on it later like this:

$child_ticket->Load($child_id);
$child_ticket->AddCustomFieldValue(
                                    Field => $CFName,
                                    Value => $DefaultCFValue ,
                                    RecordTransaction => 1 );

Before doing this you’ll need to check that your child ticket object was actually instantiated and you didn’t have an error of course.

1 Like

After creating the child ticket and obtaining the $child_ticket object, you use the AddCustomFieldValue method to set the value of a custom field. Replace 'YourCustomFieldName' with the actual name of your custom field and 'DesiredValue' with the value you want to set.