Foreach velocity outputting the same values | Community
Skip to main content
Elsa_Man3
Level 2
Apr 28, 2020 7:56 PM UTC
Solved

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!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
Apr 28, 2020 8:36 PM UTC

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

 

You want

 

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

4 replies

SanfordWhiteman
Level 10
Apr 28, 2020 8:22 PM UTC

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

 

Translate
Elsa_Man3
Elsa_Man3Author
Level 2
Apr 28, 2020 8:26 PM UTC

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>
Translate
SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
Apr 28, 2020 8:36 PM UTC

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

 

You want

 

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