Trying to Scrip grouping of 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. For some reason it was working
fine at one point, and I thought I was done. Left it alone over the weekend
and on Monday morning it stopped working completely. Nothing was changed on
the server since I’m the only person with admin access. I made some changes
to the scrip for debugging purposes and found that it is failing here:

$startUnit = $ticket->CustomFieldValues(‘Unit Where Issue
Begins’)->Next->Content;

It doesn’t fail initially, but rather runs through the search list until it
ends. That’s where the problem occurs. My thougts are that when it hits
the end of the list it fails here due to no ticket and therefore no CF to
pull data from. I could be wrong but that is what it appears to be doing.
Anyway 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/Trying-to-Scrip-grouping-of-tickets-tp26780002p26780002.html