Using Freemarker to loop over results in an email step

Trying to use a dataset in a Freemarker template, not having much luck.
If I do
<#list output_data as output> Country: ${output.Country} </#list>
It tells me that output_data evaluates as a string
freemarker.core.NonSequenceOrCollectionException
For "#list" list source: Expected a sequence or collection, but this has evaluated to a string (wrapper: f.t.SimpleScalar): ==> output_data [in template "tmpl0" at line 1, column 8] ---- FTL stack trace ("~" means nesting-related): - Failed at: #list output_data as output [in template "tmpl0" at line 1, column 1] ----
If I do
<#list ${output_data} as output> Country: ${output.Country} </#list>
it tells me I can't reference a variable with ${} and that I should use the format posted in the 1st attempt.
freemarker.core.ParseException
Syntax error in template "tmpl0" in line 1, column 8: You can't use ${...} (an interpolation) here as you are already in FreeMarker-expression-mode. Thus, instead of ${myExpression}, just write myExpression. (${...} is only used where otherwise static text is expected, i.e., outside FreeMarker tags and interpolations, or inside string literals.)
Has anyone successfully looped over a dataset in Freemarker?
Answers
-
Hi @allan
,Checking the "As HTML variable" option for a dataset, only makes the dataset available in the message as a string variable corresponding to an HTML table of the data. So it is not possible to loop over it, and since <#list> expects a collection you get this error.
Depending on what you want to achieve, a better solution might be to use a custom Python script for your scenario in Steps > + Add Step > Execute Python Code. You can find more information on this here.
Hope this helps !