Scrip to create multiple child tickets

Hi everyone,

I have a Select Multiple custom field called ‘Client’. I want my scrip to
create a child ticket for each client selected. So far, my scrip works, but
only creates 1 child ticket, no matter how many clients are selected. Here
is my current scrip:

RT 3.6.5

Description: Create multiple child tix
Condition: User Defined
Action: Create Tickets
Template: Custom Template: Create multiple child tickets
Stage: Transaction Create

Custom condition:
if ($self->TransactionObj->Type ne ‘Create’ &&
$self->TicketObj->FirstCustomFieldValue(‘Client’) eq 'client1) {
return 1;
}

if ($self->TransactionObj->Type ne ‘Create’ &&
$self->TicketObj->FirstCustomFieldValue(‘Client’) eq ‘client2’) {
return 1;
}

return 0;

Here is the Template code:
===Create-Ticket: client
({$Tickets{‘TOP’}->FirstCustomFieldValue(‘Client’)})
Depended-On-By: {$Tickets{‘TOP’}->Id()}
Owner: testuser
Queue: Client Issues
Content: This ticket has been auto-created.
ENDOFCONTENT

Is there anyone that can help me identify why only 1 child ticket is being
created, and not multiple? I obviously have limited skills here, so any
help would be greatly appreciated! Please please help!

Thanks so much!
Jonathan
View this message in context: http://old.nabble.com/Scrip-to-create-multiple-child-tickets-tp27714242p27714242.html

Jonathan,
I’m playing with a similar problem. Somewhere on this list I found the
code that allows you to create the child tickets as a custom scrip
action.

I’m using the following to create my approval tickets. The custom file
Approvers is a comma-delmited list of email addresses. A ticket is
create for each e-mail address in the list. Should be able to modify
this to work for your situation. I haven’t figured out how to add the
date, a custom field, or content with this method…

Alterntively, you could create a separate scrip with a different custom
condition for each client custom field value.

Here is what I did:

Scrip Configuration:
Condition: User Defined or As Required
Action: User Defined
Template: Global template: Blank
Stage: Transaction Create

my $queue_name = ‘___Approvals’;
my $cf_Approver = ‘Approvers’;
my $override_approver = ‘emailaddress@domain.com’;
my $ticket = $self->TicketObj;
my $req_addr = $self->TicketObj->RequestorAddresses;
my $approvers_list = $ticket->FirstCustomFieldValue($cf_Approver);
my @approvers_array = split(’,’,$approvers_list);
my $child_ticket = RT::Ticket->new ( $RT::SystemUser );
$RT::Logger->info( “> Scrip #74 - Number of approvers: @approvers_array
\n” );
foreach my $approver (@approvers_array) {
my $required = @required_array[$int];
$RT::Logger->info( “> Scrip #74 - Ticket for Approver $approver\n” );
$RT::Logger->info( “> Scrip #74 - Required Status $required\n” );
my ($child_id, $child_transobj, $errormsg ) =
$child_ticket->Create(
Queue => $queue_name ,
Subject => “Approval for ticket: " . $ticket->id . " - " .
$ticket->Subject,
Cc => $override_approver,
RefersTo => $ticket->id ,
DependedOnBy => $ticket->id ,
Type => “approval” ,
Reqestor => $req_addr,
Owner => $approver,
AdminCc => $approver,
);
unless ( $child_id ) {
$RT::Logger->debug(”>>Error : ". $errormsg);
return undef ;
}
}
return 1;

Hi everyone,

I have a Select Multiple custom field called ‘Client’. I want my scrip
to
create a child ticket for each client selected. So far, my scrip works,
but
only creates 1 child ticket, no matter how many clients are selected.
Here
is my current scrip:

RT 3.6.5

Description: Create multiple child tix
Condition: User Defined
Action: Create Tickets
Template: Custom Template: Create multiple child tickets
Stage: Transaction Create

Custom condition:
if ($self->TransactionObj->Type ne ‘Create’ &&
$self->TicketObj->FirstCustomFieldValue(‘Client’) eq 'client1) {
return 1;
}

if ($self->TransactionObj->Type ne ‘Create’ &&
$self->TicketObj->FirstCustomFieldValue(‘Client’) eq ‘client2’) {
return 1;
}

return 0;

Here is the Template code:
===Create-Ticket: client
({$Tickets{‘TOP’}->FirstCustomFieldValue(‘Client’)})
Depended-On-By: {$Tickets{‘TOP’}->Id()}
Owner: testuser
Queue: Client Issues
Content: This ticket has been auto-created.
ENDOFCONTENT

Is there anyone that can help me identify why only 1 child ticket is
being
created, and not multiple? I obviously have limited skills here, so any
help would be greatly appreciated! Please please help!

Thanks so much!
Jonathan