Replace requestor email with email from content body

Hello,

I’m trying to update a “ticket” before the first email is sent out to a dummy from email.

Under the Basic Section:
I choose User Defined for both Condition and Action, then Blank for Template.

Under User Defined Condition and Action:
Custom Condition:
I want to check if Subject matches Regex.
my $subject = $self->TicketObj->Subject;
if ($subject =~ m/^Regex/g) {
return 1;
} else {
return 0;
}

Custom Action Preparation Code:
Grab actual email from ticket body, remove dummy email and add actual email from content body
$content = $self->TransactionObj->Content;
my ($email) = $content =~ /^Email: (.*)/;
$self->TicketObj->DeleteWatcher(
Type => ‘Requestor’,
Email => ‘dummy@email.com’
);
$self->TicketObj->AddWatcher(
Type => ‘Requestor’,
Email => $email
);

I’m not getting desired result.

Any suggestion is appreciated.

Hi @d14

What is the result you get? Did you debug it in any way?

I do the same thing you want to do with the methods you use.

Condition: On Create with template Blank.
Action: User Defined
Custom condition: empty
Custom action preparation code: Test, validity; delete and add requestor
Custom action commit code: Do some replacment in content and set some CF

First things:

  • You have to ‘return 1;’ in preparation code and commit code.
  • You maybe should use condition On Create
  • and test your additional condition in preparation code and ‘return 0;’ if it fails

As far as I know the $self->TransactionObj->Content; is not availiable in the preparation code. You have to test it. It is availiable in the commit code.

If you send the first email with a second Scrip it will be no problem to set the requestor in commit code.

At all it was useful to use the

$RT::Logger->info()

to write into RT.log based upon result of the method.

my $ticket = $self->TicketObj;
my $log_tag = $ticket->QueueObj->Name . "[System #" . $ticket->id . "]: "; 
my $subject = $self->TicketObj->Subject;
[...]
$RT::Logger->info($log_tag . "entering preparation code");

if ($subject =~ m/^Regex/g) {
  $RT::Logger->info($log_tag . "found Regex, continue");
  if ($ticket->DeleteWatcher( Type => Requestor, Email => "dummy\@email.com" )) {
    $RT::Logger->info($log_tag . "Requestor deleted");
  } 
  else {
    $RT::Logger->error($log_tag . "Requestor deletion failed");
  }
  [...]
  return 0;
} else {
  $RT::Logger->info($log_tag . "Regex not found, leaving");
  return 0;
}

Regards, Andre.

Thanks @rubberduck . I could remove and add the requestor as needed following your guide. my $content = $self->TicketObj->Transactions->First->Content; in the commit code was used to search the ticket content, which worked great. I still have an issue with the email being sent to the dummy email before I updated to the actual email from the ticket content, even when I moved the Scrip to the top so it runs first before any other scrip.

This ist right @d14 . The first email is generated at ticket-creation right after ‘preparation code’ and before ‘commit code’ for condition “On Create”. These scrips are processed first.

So you have to use “On Create” and remove the dummy-email in preparation and set the new one in commit. The newly inserted address will not receive a creation-email unless you use a second scrip after this one.

The issue is, you got the true email-address in the first transaction after ticket creation. At this point the first email is already processed. Maybe it is another way to transport the true address via subject or as email-header.

Changed: It is possible to do all in preparation code. Thanks @d14

The scrips on ticket-creation are quite tricky, anyway.

Regards, Andre.

Thanks, @rubberduck. I was able to prevent RT from sending an email to dummy email. Unfortunately, there’s no other way for me to get the new email in commit, so using another scrip won’t be of much help.

Thanks,
D14.

$content = $self->TicketObj->Transactions->First->Content; worked in Custom action preparation code: and I want able to get content and update the requestor before the first email is sent out. So, the actual email now gets the email instead of the dummy email.

Thanks,
D14.

That is nice, so luckily it was wrong in my memory one only can access the content in commit code. Thanks for feedback.

What was the real issue in your code or the key leads to working scrip?

Regards, Andre.

Working scrip:
Custom Action preparation code:

my $T_Obj = $self->TicketObj;
my $subject = $T_Obj->Subject;

if ($subject =~ m/^Regex/g) {

   $content = $T_Obj->Transactions->First->Content;

   my ($email) = $content =~ /^Email: (.*)/;
     $self->TicketObj->DeleteWatcher(
          Type => ‘Requestor’,
         Email => ‘dummy@email.com’
      );
      $self->TicketObj->AddWatcher(
         Type => ‘Requestor’,
         Email => $email
      );
   return 1;
} else {
   return 0;
}

Then in Custom Action Commit Code I only have return 1

Useful snippet, thanks.

I used it to fix a little issue where some updates are emailed in from our customer portal, but the portal doesn’t really have the ability to add custom headers to fix up the ticket using RT::Extension::CommandByMail.

There are “smart quotes” in your example which are a little dangerous in code.

I changed:

$content = $T_Obj->Transactions->First->Content;

to:

my $content = $T_Obj->Transactions->First->Content;
1 Like