I'm trying to pass some information into a Custom ...
# advancedpdf
n
I'm trying to pass some information into a Custom template using the following,
Copy code
var items = getBulkItems(parameters);
renderer.addCustomDataSource({
    alias: "ITEMS",
    format: render.DataSource.JSON,
    data: JSON.stringify(items)
});
The
items
I am passing in looks like this
Copy code
var items = { 'items': [], 'units': units }; // Array items is populated later
I am able to get and render the Array of Items in the template using,
Copy code
<table style="width: 100%; margin-top: 5px;" colspan="10">
    <#if ITEMS?has_content>
        <#list ITEMS.items as item>
            <#if item_index==0>
                <thead>
                    <tr>
                        <th colspan="2">Item - Description</th>
                    </tr>
                </thead>
            </#if>
            <tr>
                <td colspan="2">${item.name}</td>
            </tr>
        </#list>
    </#if>
</table>
But I am unable to render the units passed in.
Copy code
<#if ITEMS?has_content>
    <#if ITEMS.units?has_content> Units: ${ITEMS.units} </#if>
</#if>
Sorry this was rather long, but why can I not access the units variable?
e
Hi @nathanw. looking at your code, for units it looks like you are referencing the passed alias instead of the single item. In other words the code should be
<#if item.units?has_content> Units: ${item.units} </#if>
n
@Eric Schultz Thanks for the review, the reference to the alias was intentional since units is an attribute on the base object.
k
@nathanw - did you get this resolved? I don't know if this helps, but did you try using the format of 'OBJECT' instead of 'JSON' ?
Copy code
RENDERER.addCustomDataSource({
                alias: 'items',
                format: render.DataSource.OBJECT,
                data: items
            });
n
@Katie V I did, It was something irrational yet typical of NetSuite, I simply rearranged the order or the Attributes and it works. So instead of
var items = { 'items': [], 'units': units };
I use this
var items = { 'units': units, 'items': [] };
With my limited understanding of js I don't think this would make any difference...
👍 1
k
Interesting!!!!!!