I have a suitelet that is printing a saved search ...
# suitescript
k
I have a suitelet that is printing a saved search with grouped results using an advanced pdf template. The headers of the saved search print fine, but it is not printing the results. For example.
Copy code
<body padding="0.5in 0.5in 0.5in 0.5in" size="Letter">
    <table><#list results as result><#if result_index == 0>
<thead>
	<tr>
	<th>${result.internalId@label}</th>
	<th>${result.entityid@label}</th>
	<th>${result.altname@label}</th>
	</tr>
</thead>
</#if><tr>
	<td>${result.internalid}</td>
	<td>${result.entityid]}</td>
	<td>${result.altname}</td>
	</tr>
	</#list></table>
</body>
The search is grouped by entityid and uses MIN for alt name. The result.entityid@label prints fine, but the row values do not.
s
After a quick look at the code, I see a PDF being rendered in two places, the first with renderer and newfile, and the second with the generatePDFContents function and pdfContents, but neither of those files is used again in the script after being generated, so how are you getting the output? Also, the generatePDFContents function is setting the templateName to
'LF | Component Needed Template'
, which means that the PDF template would need to reference that as the variable name. I don’t know how the advanced templates work with spaces in the templateName, as I’ve never tried it. I would stick to a simpler templateName, like
'results'
Also, the search results refer to a workorder search that only has two columns defined: GROUP(item) and SUM(quantity). I don’t see entityid or altname in any of the search columns
k
@scottvonduhn why would you need to see entityid or altname?
s
The search is grouped by entityid and uses MIN for alt name.
The result.entityid@label prints fine, but the row values do not.
is that not what you said?
k
that was just sample from another pdf template
Copy code
<table style="width: 837px;"><#list results as result><#if result_index == 0>
<thead>
	<tr>
	<th style="width: 369px;">${result.item@label}</th>
	<th style="width: 433px;">${result.quantity@label}</th>
	</tr>
</thead>
</#if><tr>
	<td style="width: 369px;">${result.item.values.value}</td>
	<td style="width: 433px;">${result.quantity}</td>
	</tr>
	</#list></table>
This to display in its place
I am sorry about the confusion
s
That makes more sense
k
The original was {result.item
s
I have not worked with Grouped/Summary columns in an advanced PDF before, but I do know that when the results are serialized to JSON for a Map/Reduce script, the columns end up with a new column name of “GROUP(item)” and “SUM(quantity)” I’d hope that Netsuite would be consistent here, but it’s possible they are not.
Also, I have generally not had luck accessing sub-elements of columns, since I believe NetSuite does not load them, so
result.item.values.value
may not work at all.
perhaps try:
${result['GROUP(item)']}
or just reverting back to
result.item
k
I got an outofBounds exception for Group(item)
its being very difficult
s
what do you get with result.item?
k
A pdf template with jus the header
s
what do you get when you try using
${result?keys}
?
that should show the available keys for the result hash
though I have had trouble using it in NetSuite before with some objects
or, instead of that:
Copy code
<#list result?keys as column>${column}</#list>
k
For "?keys" left-hand operand: Expected an extended hash, but this has evaluated to a sequence+hash (wrapper: com.netledger.templates.model.ListModel): ==> result [in template "template" at line 61, column 37]
s
yeah, i expected that might happen
k
I am trying to second options
I got an error with the second one asl well
The following has evaluated to null or missing: ==> result [in template "template" at line 65, column 9] ---- Tip: If the failing expression is known to legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present#elsewhen-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ----
s
The way I’d approach it would be to remove the GROUP and SUM summary fucntions from the search. Then, sort the results by item, and do the item grouping/ summing of quantity in the template itself
k
s
Since I am not sure what the format for accessing GROUP and SUM columns is.
SA 39168 says that
displaying grouped result is one of its limitations.
k
I am a junior dev. I don't understand your approach.
I would need sometime to talk it over
s
You’d need to set up some simple variables in the freemarker template. IT’s not very hard actually.
Here’s the basics
some of that may need to be adjusted, and i’d verify the math is working as expected
but essentially, you’d be resetting a quantity sum each time you hit a hew item. For it to work, the list would also need to be sorted by item
Copy code
<#assign prev_item = results[0].item>
<#assign quantity = 0>

<#list results?sort_by('item') as result>
  <#assign item = result.item>
  <#assign new_item = (item != prev_item)>

<#if result_index == 0>
  <thead>
	<tr>
	  <th>${result.item@label}</th>
	  <th>${result.quantity@label}</th>
	</tr>
  </thead>
</#if>

  <#if new_section>
    <tr>
	  <td>${prev_item}</td>
	  <td>${quantity}</td>
	</tr>
	<#assign quantity = 0>
  </#if>

  <#assign prev_item = item>
  <#assign quantity = quantity + result.quantity?number>
</#list>