Basic help with scrip to action on matching subject / content on creae

Howdy all! I’m fairly new to RT Administration and PERL, so I’m hoping to run by a fairly easy use-case that I’m having challenges with. Running RT 4.4.3

I’ve been toying around with several articles / posts and haven’t been able to get either solution to work.

Use case - Send a specific template email to Requestor based on content in the Subject or the Body of the email On Create for a specific Queue

I’ve tried to follow-
https://rt-wiki.bestpractical.com/wiki/ReplyBasedUponContent

I’ve created a script under the target queue with the following and enabled it after creating a template. Testing completed with the words “Open Sesame” in the body of the email when creating a ticket (Goal is eventually subject line)

Description: Special Use Case
Condition: User Defined
Action: Notify Requestors
Template: Special Use Case

Custom Condition:
my $Attachment = $self->TicketObj->TransactionObj->Attachments;
my $Content = $Attachment->First->Content;
if( $Content =~ m/Open Sesame/ ){
$Ticket->SetStatus( Status => ‘open’ , Force => 1,);
return 1;
}

Custom Action Preparation Code:
-Have tried leaving blank

-Also have tried
return 1;

Custom Action Commit Code:
Same as above, tried both

When enabling it, I’m just not getting RT to send the email to me as the requestor using the template. No errors when saving the scrip.

Second option I tried to follow -

For this one, similar settings, but I tried to only use the “Custom Condition” seen in the last post by the OP:

my $match = “Backup Report [Successful]”;
my $t_subject = $self->TicketObj->Subject;
if ( $t_subject !~ /$match/i ) {
return 1;
}
else {
return 0;
}

I’m getting an error when saving the scrip -
“Couldn’t compile CustomIsApplicableCode codeblock ‘my $match = “Backup Report [Successful]”; my $t_subject = $self->TicketObj->Subject; if ( $t_subject !~ /$match/i ) { return 1; } else { return 0; }’: Unrecognized character \x{201c}; marked by <-- HERE after $match = <-- HERE near column 19 at (eval 1363) line 1. Stack: [(eval 1363):1] [/opt/rt4/share/html/Admin/Scrips/Modify.html:139] [/opt/rt4/share/html/Admin/autohandler:49] [/opt/rt4/sbin/…/lib/RT/Interface/Web.pm:697] [/opt/rt4/sbin/…/lib/RT/Interface/Web.pm:376] [/opt/rt4/share/html/autohandler:53]”

Can anyone throw me a bone? I am learning, so I do plan to take a functional solution and continue to build on it.

If I’m using a built in Action (Such as Notify Requestors), do I still need to enter “return 1;” in the Custom Action Preparation Code and Custom Action Commit code?

Also, many topics / pages list a field I’m not seeing called “Stage”, is this because of my RT version?

Thanks in advance!

A couple of things.

Use case - Send a specific template email to Requestor based on content in the Subject or the Body of the email On Create for a specific Queue

  1. By default you have the following scrip " On Create Autoreply To Requestors" so we don’t want this scrip to run if the condition is met. So you need to change the “Condition” to user defined:
return 0 unless $self->TransactionObj->Type eq 'Create';
return 0 if $self->TicketObj->Subject eq 'Open Sesame';
return 1;

Then you can create your new RT::Scrip and make it look exactly like the scrip from above except with the condition inverted:

return 0 unless $self->TransactionObj->Type eq 'Create';
return 1 if $self->TicketObj->Subject eq 'Open Sesame';
return 0;

and use the other email template!

Thanks knation for the response!

I do see the default scrip in the specific queue in question, and in global - they are both disabled (We don’t currently use any Autoreply to Requestors")

Would the recommendation still be relevant?

From what I’m understanding, if I had that enabled (Default scrip to Autoreply to requestors on create) you are recommending I disable it and replace it with two scrips, one returning false to send the “standard” auto reply and the second returning “true” to send the “special” autoreply if it matches the logic? Basically a fork in the road for that tickets being created in that queue.

When I use these in the custom condition field and with Condition:“User Defined”, Action:“Notify Requestors”, would I need to input anything in “Custom Action Preparation Code” and “Custom Action Commit code”? Or would I only need to do that in conjunction with “Action”: User Defined?

If you don’t want the autoreply scrip then you can just make the new scrip!

Requestors”, would I need to input anything in “Custom Action Preparation Code” and “Custom Action Commit code”? Or would I only need to do that in conjunction with “Action”: User Defined?

Correct you don’t need to put anything there if you are using an existing action

Awesome! I got this working using the AutoReply to requestors built in Action (couldn’t get it to work with the built in Notify Requestors as the RT debug log kept leaving the requestor (or TO:) blank and therefore wouldn’t deliver the email to the requestor.

Two followups if I may -

Is there a “LIKE” operator that could be used instead of “eq” ? For matching subjects such as “FWD: Open Sesame” (not only subject “Open Sesame”). I’m struggling finding a good cliff notes to start with for Perl (which I’m assuming is Perl5).

If I wanted matches for these tickets by subject line to also perform other actions in addition to the auto respond to requestors (such as setting a custom field and resolving the ticket) would the best practice include separate scrips with custom action prep/commit codes for each step, or moving to one scrip and one big user defined custom action prep/commit code that would accomplish the workflow all at once?

Kudos again for the assistance!

You can use a regex for that, something like $subject =~ /Open Sesame/ is probs enough. You can test with a tool like this:

Or a standalone Perl script, as the syntax is a little different for Perl ( things like “@” need to be escaped ).

If I wanted matches for these tickets by subject line to also perform other actions in addition to the auto respond to requestors (such as setting a custom field and resolving the ticket) would the best practice include separate scrips with custom action prep/commit codes for each step, or moving to one scrip and one big user defined custom action prep/commit code that would accomplish the workflow all at once?

I’d be tempted to split the logic up if there are a lot of other steps. If its relatively simple then one scrip action seems fine.

If you end up using the same condition code in a few scrips it may be worth looking at putting that condition on file so it can be used as an option from the condition drop down. This requires creating a condition module file in your /opt/rt4/local/... directory and then using the file in a “Condition” via Admin->Global->Conditions

Lovely, thanks for the prompt response! You rock!

1 Like

return 0 unless $self ->TransactionObj->Type eq 'Create' ;

return 1 if $self ->TicketObj->Subject =~ /subject1/| $self ->TicketObj->Subject =~ /subject2/;

return 0;

Here’s the custom condition that is working for me. Enhanced with an OR statement and matches the subject string with any prepended or appended text.

1 Like