Combine HTML/PERL in RT Template

Good Day

I am trying to perform an action using Perl and also attach HTML Formatted Ticket Information.

Perl Part

To: {  my $ticket = $Ticket;
  my $name = '';
  my $cfName = '';
  my $ticketcfValue = '';
  my $cfValues = '';
  my $val = 'not set';

  my $CustomFields = $ticket->QueueObj->TicketCustomFields();
  while (my $CustomField = $CustomFields->Next())
  {
    $name = $CustomField->Name;
    if ($name eq 'Allocated To')
    {
      # get the currently selected Resolver name
      $ticketcfValue = $ticket->CustomFieldValuesAsString($name);
  
        # load all the possible values for Resolver Names
        my $cf = RT::CustomField->new(RT::SystemUser);
        $cf->LoadByName(Name => 'Allocated To');
        my $cfValues = $cf->Values;

        while (my $cfValue = $cfValues->Next)
        {
        if ($cfValue->Name eq $ticketcfValue)
        {
          $val = $cfValue->Description;
        }
      }
    }
  }
  $val; }

After the above action I would like to send ticket information in HTML Format

HTML Part
<p>Greetings,</p>

<p>A new incident has been created: <b>{$Ticket->Subject()}</b>.</p>


<hr/>

<table border="0">
<tr><td align="right"><b>Subject:</b></td><td>{$Transaction->Subject || $Ticket->Subject || "(No subject given)"} </td></tr>
<tr><td align="right"><b>Status:</b></td><td>{$Ticket->Status}</td></tr>

If I add Content Type: text/html on the beginning of the template then the perl part does not work.

How do I combine the two?

Does that Perl bit work when testing without the text/html line?

So this is all one template? And you’re saying its not working if you just add the line

Content-type: text/html

to the top of the template? What happens if you put the Content-type line after the To:?

I assume you need to use the $OUT variable in that Perl block right?

@knation yes the Perl bit works without the text/html line.

@GreenJimll It is one Template.

I tried to put it below To:

To:
Content-Type: text/html
 {  my $ticket = $Ticket;
  my $name = '';
  my $cfName = '';
  my $ticketcfValue = '';
  my $cfValues = '';
  my $val = 'not set';

  my $CustomFields = $ticket->QueueObj->TicketCustomFields();
  while (my $CustomField = $CustomFields->Next())
  {
    $name = $CustomField->Name;
    if ($name eq 'Allocated To')
    {
      # get the currently selected Resolver name
      $ticketcfValue = $ticket->CustomFieldValuesAsString($name);
  
        # load all the possible values for Resolver Names
        my $cf = RT::CustomField->new(RT::SystemUser);
        $cf->LoadByName(Name => 'Allocated To');
        my $cfValues = $cf->Values;

        while (my $cfValue = $cfValues->Next)
        {
        if ($cfValue->Name eq $ticketcfValue)
        {
          $val = $cfValue->Description;
        }
      }
    }
  }
  $val; }


<p>Greetings,</p>

<p>A new incident has been created: <b>{$Ticket->Subject()}</b>.</p>


<hr/>

<table border="0">
<tr><td align="right"><b>Subject:</b></td><td>{$Transaction->Subject || $Ticket->Subject || "(No subject given)"} </td></tr>
<tr><td align="right"><b>Status:</b></td><td>{$Ticket->Status}</td></tr>
{ ($Ticket->FirstCustomFieldValue('Severity')) ? "<tr><td align='right'><b>Severity:</b></td><td>".$Ticket->FirstCustomFieldValue('Severity')."</td></tr>\n" : "" } 

It does not work.

@knation how do I add the $OUT to the perl block?

Each header needs its own line, you are putting the “To:” as “Content-Type: text/html…” in your example you just posted. Make the first line the content type then the next one the “To” block

Content-Type: text/html

<p>Greetings,</p>

<p>A new incident has been created: <b>{$Ticket->Subject()}</b>.</p>


<hr/>

<table border="0">
<tr><td align="right"><b>Subject:</b></td><td>{$Transaction->Subject || $Ticket->Subject || "(No subject given)"} </td></tr>
<tr><td align="right"><b>Status:</b></td><td>{$Ticket->Status}</td></tr>
{ ($Ticket->FirstCustomFieldValue('Severity')) ? "<tr><td align='right'><b>Severity:</b></td><td>".$Ticket->FirstCustomFieldValue('Severity')."</td></tr>\n" : "" } 


To: {  my $ticket = $Ticket;
  my $name = '';
  my $cfName = '';
  my $ticketcfValue = '';
  my $cfValues = '';
  my $val = 'not set';

  my $CustomFields = $ticket->QueueObj->TicketCustomFields();
  while (my $CustomField = $CustomFields->Next())
  {
    $name = $CustomField->Name;
    if ($name eq 'Allocated To')
    {
      # get the currently selected Resolver name
      $ticketcfValue = $ticket->CustomFieldValuesAsString($name);
  
        # load all the possible values for Resolver Names
        my $cf = RT::CustomField->new(RT::SystemUser);
        $cf->LoadByName(Name => 'Allocated To');
        my $cfValues = $cf->Values;

        while (my $cfValue = $cfValues->Next)
        {
        if ($cfValue->Name eq $ticketcfValue)
        {
          $val = $cfValue->Description;
        }
      }
    }
  }
  $val; }

Do you mean like this?

No, you’re splitting the headers and body now. All the headers need to be at the top.

Content-Type: text/html
To:

HTML

regards
Garry

Content-Type: text/html
To: 
{  my $ticket = $Ticket;
  my $name = '';
  my $cfName = '';
  my $ticketcfValue = '';
  my $cfValues = '';
  my $val = 'not set';

  my $CustomFields = $ticket->QueueObj->TicketCustomFields();
  while (my $CustomField = $CustomFields->Next())
  {
    $name = $CustomField->Name;
    if ($name eq 'Allocated To')
    {
      # get the currently selected Resolver name
      $ticketcfValue = $ticket->CustomFieldValuesAsString($name);
  
        # load all the possible values for Resolver Names
        my $cf = RT::CustomField->new(RT::SystemUser);
        $cf->LoadByName(Name => 'Allocated To');
        my $cfValues = $cf->Values;

        while (my $cfValue = $cfValues->Next)
        {
        if ($cfValue->Name eq $ticketcfValue)
        {
          $val = $cfValue->Description;
        }
      }
    }
  }
  $val; }

<p>Greetings,</p>

<p>A new incident has been created: <b>{$Ticket->Subject()}</b>.</p>


<hr/>

<table border="0">
<tr><td align="right"><b>Subject:</b></td><td>{$Transaction->Subject || $Ticket->Subject || "(No subject given)"} </td></tr>
<tr><td align="right"><b>Status:</b></td><td>{$Ticket->Status}</td></tr>
{ ($Ticket->FirstCustomFieldValue('Severity')) ? "<tr><td align='right'><b>Severity:</b></td><td>".$Ticket->FirstCustomFieldValue('Severity')."</td></tr>\n" : "" } 

This does not work.

The to section is meant to send out an email to the custom field populated with a mail address.

When trying it out the above way it does not work.

@G.Booth

I tried that and it does not work.

I tried the HTML First and Perl after with that set as the header and vice versa.

The To: and the open brace need to be on the same line, as your Perl is supposed to be generating the email address (I assume that’s what its trying to do at least!).

@GreenJimll it works :grinning::grinning::grinning::grinning::grinning::grinning:

Thank you very much !!!

@knation @GreenJimll Thank you guys for always assisting !!!