Foreach velocity outputting the same values | Community
Skip to main content
Elsa_Man3
New Participant
April 28, 2020
Solved

Foreach velocity outputting the same values

  • April 28, 2020
  • 1 reply
  • 3278 views

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.
Best answer by SanfordWhiteman

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

 

You want

 

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

1 reply

SanfordWhiteman
New Participant
April 28, 2020

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

 

Elsa_Man3
Elsa_Man3Author
New Participant
April 28, 2020

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
SanfordWhitemanAccepted solution
New Participant
April 28, 2020

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

 

You want

 

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