Skip to content

Instantly share code, notes, and snippets.

@acobaugh
Created April 3, 2012 18:32
Show Gist options
  • Save acobaugh/2294490 to your computer and use it in GitHub Desktop.
Save acobaugh/2294490 to your computer and use it in GitHub Desktop.
## Prep
my $from = 'helpdesk@psu.edu';
if (lc($self->TicketObj->RequestorAddresses) ne $from) {
$RT::Logger->info("Ticket is NOT from $from");
return 0;
} else {
$RT::Logger->info("Ticket IS from $from");
return 1;
}
######################
## Cleanup
my $cfName = 'SERVICEDESK-Key';
my $subject = $self->TicketObj->Subject;
my $cfObj = RT::CustomField->new( $RT::SystemUser );
if ($subject =~ /\[SERVICEDESK\] \(((SD|Listserv|LISTSERV)-[0-9]+)\)/) {
my $key = $1;
$RT::Logger->info("SERVICEDESK Ticket with Key $key");
# Add the custom field
$cfObj->LoadByName( Name => "$cfName" );
$self->TicketObj->AddCustomFieldValue( Field => $cfObj, Value => "$key" );
# set up search
my $tickets = new RT::Tickets(RT->SystemUser);
$tickets->LimitCustomField(
CUSTOMFIELD => $cfObj->Id(),
OPERATOR => '=',
VALUE => $key
);
# iterate over tickets
my $i=0;
while (my $ticket = $tickets->Next) {
# skip if this is us
if ($ticket->id != $self->TicketObj->id) {
$i++;
$RT::Logger->info("Adding RefersTo link id " . $ticket->id . " to ticket id " . $self->TicketObj->id);
$self->TicketObj->AddLink(Type=>'RefersTo',Target=>$ticket->id);
# Alternative is to merge:
# $self->TicketObj->MergeInto($ticket->id);
}
} # END while()
} # END if()
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment