<div>Hi, </div>
<div> </div>
<div>I'm working on a scrip that will grab the subject of a new ticket and compare it with existing ticket. If a match is found, the scrip will merge the ticket. I have the script below. </div>
<div> </div>
<div>I have additional requirement where I'll ignore preceeding characters and merge if the next characters matched. </div>
<div> </div>
<div>An example, this tickets should merge:  </div>
<div> </div>
<div>existing ticket: "Subject 1"</div>
<div>new ticket: "RE: Subject 1"  </div>
<div> </div>
<div>this example should merge also </div>
<div> </div>
<div>existing ticket: "Subject A"</div>
<div>new ticket: "Fw: Subject A"</div>
<div> </div>
<div>this example, should not merge: </div>
<div> </div>
<div> existing ticket: "Subject 2GO"</div>
<div> new ticket: "Subject Any"</div>
<div> </div>
<div>Thanks in advanced! </div>
<div> </div>
<div> </div>
<div>my $problem_desc = undef;</div>
<div>my $Transaction = $self->TransactionObj;<br>my $subject = $Transaction->Attachments->First->GetHeader('Subject');</div>
<div>$problem_desc = $subject<br>$RT::Logger->debug("This is the subject to match: $problem_desc");</div>
<div># look for subject on existing tickets <br>my $search = RT::Tickets->new($RT::SystemUser);<br>$search->LimitQueue(VALUE => 'IT');<br>$search->LimitStatus(VALUE => 'new', OPERATOR => '=', ENTRYAGGREGATOR => 'or');<br>
$search->LimitStatus(VALUE => 'open', OPERATOR => '=');</div>
<div>if ($search->Count == 0) { return 1; }<br>my $id = undef;<br>my $same_desc = undef;<br>while (my $ticket = $search->Next) {<br>    # Ignore this ticket that opened this transaction <br>    next if $self->TicketObj->Id == $ticket->Id;<br>
    $ticket->Subject = $same_desc<br>    if ($same_desc eq $problem_desc){<br>       # Found the same subject <br>       $RT::Logger->debug("SAME $same_desc and $problem_desc");  <br>       $id = $ticket->Id;<br>
       $RT::Logger->debug("Merging ticket " . $self->TicketObj->Id . " into $id because of OA number match.");<br>       $self->TicketObj->MergeInto($id);<br>    } <br>}</div>
<div><br>$id || return 1;<br>1;</div>