if I have a custom field containing JSON how do I ...
# ask-stanley-ai
n
if I have a custom field containing JSON how do I reference that in an advanced PDF to make use of the key/value pairs and does it need to be an array of objects?
c
AI generated answer (using internal Slack threads):
To reference a custom field containing JSON in an advanced PDF and make use of the key/value pairs, you would need to parse the JSON string into an object. This can be done using the
eval()
function in Freemarker, which is the language used in Advanced PDF templates in NetSuite. Here is an example of how you can do this:
Copy code
freemarker
<#assign myJson = record.custbody_my_json_field?eval>
${myJson.key1}
${myJson.key2}
In this example,
custbody_my_json_field
is the script ID of your custom field, and
key1
and
key2
are keys in your JSON object. Please note that the JSON stored in the custom field should be a valid JSON string. If it's not valid, the
eval()
function will throw an error. If your JSON is an array of objects, you can loop through the array using a
<#list>
directive. Here is an example:
Copy code
freemarker
<#assign myJsonArray = record.custbody_my_json_field?eval>
<#list myJsonArray as item>
    ${item.key1}
    ${item.key2}
</#list>
In this example,
item
is each object in the array, and you can access its keys as shown. Remember to replace
custbody_my_json_field
,
key1
, and
key2
with your actual field and key names. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.847172856
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.84145689
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.836835682
Please provide your feedback on this answer.
Thank you for your feedback