Hi, I am trying to create a PDF template. However...
# advancedpdf
u
Hi, I am trying to create a PDF template. However, I have a custom field that has data in JSON format. Is there anyway we can parse the data inside the template and render in the table format. Thanks
a
Yep you can use the
eval
function - it isn't officially supported but I use it with good success
d
use ?eval_json, especially when the json is from an external source (see the warning on
?eval
and at the bottom of
?eval_json
a
For some reason I thought I tried eval_json and couldn't get it to work but eval worked for me. I'll have to give it another go if you got it to work.
d
just checked and I didn't end up using
?eval_json
myself as it wasn't available at the time (back when NS was using
v2.3.26
)
a
ok that sounds familiar
also, while
?eval
worked for me, it always gives me an error when I save the PDF template which makes me very uneasy
😬 1
d
cause of the sample data netsuite uses to validate the template. I think you have to wrap it in a bunch of checks (like
?has_content
), even though you know that the data is going to be valid JSON
a
right - I do have the
?has_content
check in there but it likely needs something more robust for the validation - the error i see is
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 these patterns:
"."
".."
<DOT_DOT_LESS>
"..*"
"?"
"??"
"!"
"["
"("
")"
<TERMINATING_EXCLAM>
---end-message---
should look for whether it starts with "["
d
<#if !record.field?starts_with('Lorem ipsum')>${record.field?eval}</#if>
😅
a
i mean, it's low effort and saves me an extra click on save when i'm editing the template, so i kinda love that
😉 1
d
also you never know when one template validation error is masking another one, so it is probably actually safer to implement something like that. My apologies to Umar for hijacking the thread
high five 1