Change email template with user defined scrip

Hey everyone,

I have the following scenario:
I have a custom fields named “type”, and i want to send a different email depending on “type”
I have tried and with some sucess altering the template using TemplateObj->SetContent()
The problem is that it writes it to the database, which i do not want since we have a lot of tickets created every second, so i need it to be concurrent

So is it possible in any way to change what i send in email “on memory”? i imagine like altering the content but not writing it to the database or sending the email and changing what is the template in a user defined action

Thank you,

In your template can you do something like

if ( $Ticket->FirstCustomFieldValue( 'Type' ) eq 'sometime' ) {
   $OUT = "Some message";
else  {
   $OUT = "Some other message";

The other option is to remove the default on correspond scrips and create your own where they are “On correspond and Type is X” but that could be tedious

I thought of that option, issue is that we have hundreds of templates so that option is really not maintainable

We already have a mechanism that generates those templates, ideally we would call that mechanism, receive the template, and then send an email with the received template

I am not sure if it is a best practice but you could have the template call your mechanism either through a bash script or web request:

   my $type = $Ticket->FirstCustomFieldValue( 'Type' );
    $OUT = `perl $type`;

@knation thank you! That’s what i was trying to do and it works flawlessly, thank you a lot!

1 Like