Scrip to Generate Parent Tickets

The idea here that if a specific device is down and causing an outage to a
number of systems, that when the first ticket is created and a CF is set to
"Outage" that it will generate a Parent ticket for the Outage and link any
following tickets created for that Outage. I have a partially working scrip
at this point, but am stuck on how to add a ticket to an existing Parent and
on how to generate a new ticket and set it as the Parent. Here is what I
have so far:

Action: User Defined
Template: Blank
Stage TransactionBatch

Custom Condition:

Check to confirm ticket is set to Outage

return 0 unless $self->TransactionObj->Type eq “Create”;
return 0 unless $self->TicketObj->CustomFieldValues(‘Type of
Issue’)->Next->Content eq ‘Outage’;
return 1;

Custom Action:

Search for other Outage tickets with Matching StartUnit

my $problemUnit = undef;
my $Transaction = $self->TransactionObj;
my $search = RT::Tickets->new($RT::SystemUser);
$problemUnit = $self->TicketObj->CustomFieldValues(‘Unit Where Issue
Begins’)->Next->Content;

$search->LimitQueue(VALUE => ‘Network Tech’);
#$search->LimitCustomField(CUSTOMFIELD => ‘Type of Issue’, VALUE =>
‘Outage’);
#$search->LimitCustomField(CUSTOMFIELD => ‘Customer Name’, VALUE =>
‘Master’);
$search->LimitStatus(VALUE => ‘new’, OPERATOR => ‘=’, ENTRYAGGREGATOR =>
‘or’);
$search->LimitStatus(VALUE => ‘open’, OPERATOR => ‘=’);
if ($search->Count == 0) { return 1; }
my $id = undef;
my $startUnit = undef;
my $priority = 3;

while (my $ticket = $search->Next) { #start while
# Ignore the ticket that caused this scrip to run
next if $self->TicketObj->Id == $ticket->Id;
$startUnit = $ticket->CustomFieldValues(‘Unit Where Issue
Begins’)->Next->Content;

Compare the two ‘Unit Where Issue Begins’ CFs

if ($startUnit eq $problemUnit){ #start 1st IF
	my $master = $ticket->CustomFieldValues('Customer Name')->Next->Content;

Check to see if Ticket is Master and has Child Tickets

	next unless($master eq "Master");
	if ($ticket->Members() ge 1){ #start 2nd IF

Ticket is Master/Parent -> add current Ticket as Child of Parent

	$id = $self->TicketObj->id;
	$ticket->AddLink(Type=>'MemberOf',Base=>$id);

Increment Parent ticket Priority

	my $priority = $ticket->Priority;
	$ticket->SetPriority ($priority + 1);
	return 1; #exit scrip
	} #end 2nd IF
} #end 1st IF

No Parent found -> Create new Parent and link as Child

my $child_ticket = RT::Ticket->new ($RT::SystemUser);
my $typeIssue = $self->TicketObj->CustomFieldValues('Type of

Issue’)->Next->Content;
my $coop = $self->TicketObj->CustomFieldValues(‘Coop’)->Next->Content;
my $customer = ‘Master’;

$child_ticket->Create(
	Queue => 'Network Tech',
	Type => 'Ticket',
	Members => $self->TicketObj->Id
);

################ Set CustomFields in Parent ################
$child_ticket->AddCustomFieldValue(Field => ‘Coop’, Value => $coop);
$child_ticket->AddCustomFieldValue(Field => ‘Type of Issue’, Value =>
$typeIssue);
$child_ticket->AddCustomFieldValue(Field => ‘Unit Where Issue Begins’,
Value => $problemUnit);
$child_ticket->AddCustomFieldValue(Field => ‘Customer Name’, Value =>
$customer);

return 1; #exit scrip

} #end while
return 1;

All help is greatly appreciated!
View this message in context: http://old.nabble.com/Scrip-to-Generate-Parent-Tickets-tp26342398p26342398.html