How can I loop through a custom sublist/subrecord ...
# advancedpdf
n
How can I loop through a custom sublist/subrecord on a custom record in a pdf? The following doesn't return anything:
Copy code
<#list record.customrecord_dc_woline as line>
    test : ${line.custrecord_dc_woline_seg_name}
    </#list>
s
#list
n
I am doing that but getting no results:
Copy code
<#list record.customrecord_dc_woline as line>
    test : ${line.custrecord_dc_woline_seg_name}
    </#list>
s
Havent done it in a while but i would reference how SOs print items that are in the Item subtab
a
@Nicholas Williams I don't think you can do it that way, unfortunately. That way I've gotten around this in the past is to use a script (or summary search-driven grouped custom field) to condense/join all your data together, and then split that string apart in your PDF template using Freemarker. That should give you a list to work with for outputting on the PDF.
n
@al3xicon thanks. That is where i am at now. When i put a string array into a custom field. Do you iterate over that the same way with <#list record.jsonfield as line> ${line.name}
a
yep
n
hm okay, not returning anything
a
did you split it first?
n
no i didn't what do i need to do?
or how in freemarker
a
something like <#list record.custrecord_customfield?split(",") as pair>
split by whatever character you use to join the data together
n
so here is the data in the custom field
Copy code
[{"name":"Customer 1","cause":"cause for customer 1","correction":"correction for customer 1","complaint":"complaint for customer 1"},{"name":"Internal 1","cause":"cause for internal 1","correction":"correction for internal 1","complaint":"complaint for internal 1"}]
a
if it is actually JSON i think you can try ?eval_json but not sure if it's implemented in NS's version of freemarker
yeah so you need to parse the JSON before you can iterate over it, simple ?split won't do it
n
how would i do that?
can you parse in freemarker?
so eval_json threw an error. ?eval by itself worked and returned the values but gives this error on saving pdf:
Copy code
Failed to "?eval" string with this error:

---begin-message---
Syntax error in ?eval-ed string in line 1, column 8:
Encountered "ipsum", but was expecting one of:
".."
<DOT_DOT_LESS>
"..*"
")"
---end-message---

The failing expression:
==> record.custrecord_dc_wo_segment_data?eval [in template "template" at line 321, column 15]

----
FTL stack trace ("~" means nesting-related):
- Failed at: #list record.custrecord_dc_wo_segment... [in template "template" at line 321, column 8]
----
w
just do (without the json) — record.custrecord_dc_wo_segment_data?eval
177 Views