Looping through Array in Template

I’ve been trying to have my email template list all the values from a select multiple values custom field and I’m running into bizarre behaviour.

I was able to find this code block that puts all the cf values into one output.

my $affNet = $Ticket->CustomFieldValues(‘Affected Networks’);
while ( my $value = $affNet->Next ) {
$OUTPUT .= $value->Content. “<br/>”;

This will output something like this in my template:

What I would like to do is push each of those into an array and print those to the email being sent.

Here is how i have it setup right now.

my $affNet = $Ticket->CustomFieldValues(‘Affected Networks’); # Example Array will be: [‘CF1’, ‘CF2’, ‘CF3’]

my @AffArray; # Array to put the values into
my $opLog; #variable to push into array

while ( my $value = $affNet->Next ) {
$OUTPUT .= $value->Content. “<br>”;

$opLog = $value->Content; # logscurrent array value
push @AffArray, $opLog; # puts value into array


When I create my ticket, and it sends an email with this template, it will only print the last array reference.

I want to know how I can print each value of the new array into the template.

Could you give an example of what the output should look like? I am confused it seems to me like the goal is to have the output look like that of the first example you gave:


I have a Select Multiple Values field with 6 options, i can’t give the real values but it’s just varchar text. Nothing fancy. I would like to print the selected values into the template as well as store them so i can create conditional code blocks controlling what will show up when certain options are selected.

Ultimately i’d like to make it look like

Networks Affected:
* CFvalue1
* CFvalue4
* CFvalue6

but what I’m getting is

Networks Affected:
* CFvalue3

It doesn’t print the first few array references, just the last in the scrip block.

I do get this error in the messages log for the array entries that don’t render.

Useless use of array element in void context at template line 20

I’d also like to store those values into an array so i can create a conditional block on who should be sent these.

For reference this is the module RT uses to parse templates:

Does something like this work?

Subject: Test

  our @values;
  my $affNet = $Ticket->CustomFieldValues( 'Affected Networks' );

  while ( my $value = $affNet->Next ) {
      next unless $value;
      my $content = $value->Content;

       $OUT .= '* ' .$content. '<br>';
       push @values, $content;


Some normal content

   if ( $values[2] eq 'dog' ) {
        $OUT = 'DOGGGGG';

The $AffArray[2]; is the return value from this block of code. Try putting $OUTPUT; just before the last closing brace.

I’ll try this and report back.