SOLVED

Re: Foreach velocity outputting the same values

Go to solution
Elsa_Man3
Level 2

Foreach velocity outputting the same values

We're trying to use the foreach directive in Velocity to list all the Order Dates that a contact had have, over time. 

 

For example, Joe Smith placed an order today and one yesterday, so in the email I want it to list out both dates. I've used this script:

 

<ul>
#foreach ($Program_Order in $Program_Order__cList)
<li>${Program_Order__cList.get(0).CreatedDate}</li>
#end
</ul>

But in the email outputs, it just lists out yesterday's date, twice. So it's recognizing that Joe has 2 order records attached to it, but only populating it with the first order's created date in the list. What am I missing in the script? 

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Foreach velocity outputting the same values

You keep getting the same index, so that's to be expected.

 

You want

 

<li>${Program_Order.CreatedDate}</li>

View solution in original post

4 REPLIES 4
SanfordWhiteman
Level 10 - Community Moderator

Re: Foreach velocity outputting the same values

Please highlight your code using the Syntax Highlighter, then we'll continue.

 

syntax_vtl.png

Elsa_Man3
Level 2

Re: Foreach velocity outputting the same values

thanks! I've edited the original post with the syntax highlighter, also below:

 

<ul>
#foreach ($Program_Order in $Program_Order__cList)
<li>${Program_Order__cList.get(0).CreatedDate}</li>
#end
</ul>
SanfordWhiteman
Level 10 - Community Moderator

Re: Foreach velocity outputting the same values

You keep getting the same index, so that's to be expected.

 

You want

 

<li>${Program_Order.CreatedDate}</li>
Elsa_Man3
Level 2

Re: Foreach velocity outputting the same values

it works great now, thank you!!