I am struggling to get "Service", "Description", "...
# advancedpdf
l
I am struggling to get "Service", "Description", "Discount" and "Subtotal" type items to print on any Advanced PDF. There are no filters (#if) on the list. Is this is a limitation of NetSuite? I remember trying to do this maybe a year ago and gave up. Thanks.
message has been deleted
d
are you able to dumb the code for the
list
and what's inside it? It might not be a filter for
itemtype
, it might be filtered on something weird like
item.quantity gt 0
l
Copy code
<table>
	<#list record.item as item>
		<#if item_index==0>
			<thead>
				<tr>
					<th class="bold background-grey">Line</th>
					<th class="bold background-grey">Description</th>
					<th class="bold background-grey">Item</th>
					<th class="bold background-grey">Qty</th>
					<th class="bold background-grey">Line Total</th>
				</tr>
			</thead>
		</#if>
			<tr>
				<td>${item_index+1}</td>
				<td>${item.description}</td>
				<td>${item.item}</td>
				<td>${item.quantity}</td>
				<td>${item.amount}</td>
			</tr>
	</#list>
</table>
@David B Thanks for trying to help. It's really quite simple. However the PDF doesn't print the types that I mentioned. Wondering if someone else can try this in their account and tell me if for example "Service" type items appear on the PDF print out.
I have found out what it is! For some reason Advanced PDF's will read commented out #if as if it wasn't commented out!!! In my example above, I (wrongly) assumed that the comments were irrelevant, so I deleted them before sending to you. So the actual original code was below. Once I deleted the commented #if then it worked fine!
Copy code
<table>
	<#list record.item as item>
		<#if item_index==0>
			<thead>
				<tr>
					<th class="bold background-grey">Line</th>
					<th class="bold background-grey">Description</th>
					<th class="bold background-grey">Item</th>
					<th class="bold background-grey">Qty</th>
					<th class="bold background-grey">Line Total</th>
				</tr>
			</thead>
		</#if>
		<!--<#if item.itemtype?starts_with("Inv") || item.itemtype?starts_with("Kit") || item.itemtype?starts_with("Non")>-->
			<tr>
				<td>${item_index+1}</td>
				<td>${item.description}</td>
				<td>${item.item}</td>
				<td>${item.quantity}</td>
				<td>${item.amount}</td>
			</tr>
		<!--</#if>-->
	</#list>
</table>
📌 1
🙌 1
m
@Lee Hopper This is really interesting, so thanks for updating us with what you found. Based on my relatively limited experience with Advanced PDFs (anyone with better knowledge, feel free to correct me), there are a few things I’d like to call out: 1.
<!-- -->
is the syntax for HTML comments 2.
<#if ></#if>
are Freemarker tags that are compiled out before the HTML is “run” to create the final document 3.
<#-- -->
is the syntax for Freemarker comments, which will remove whatever’s between the start and end as it’s being compiled, before it’s “run” to create the final document If you’d ideally like to keep that if block there (but commented out), I’d suggest replacing the
!
with a
#
in your comment and you’ll probably see the behavior you were expecting. It’s just a matter of what the comments are applied to. I only expect HTML comments to act on whatever final HTML is compiled between them, so they won’t remove Freemarker tags themselves. Since Freemarker comments are parsed by the compiler, they’ll definitely remove Freemarker tags and should (I think) also remove any HTML content between start and end.
If you have any interest in the subject, this is kinda similar to “type erasure” in TypeScript, where the final JS code that it compiles to is largely unaware of the type restrictions that were set in the original TS code. So people new to TS are often surprised to see their types not enforced at runtime. To draw the parallel, Freemarker compiles to HTML in a similar way to how TypeScript compiles to Javascript. “Runtime” for JS is when you load a page in your browser and “runtime” for you is when the final PDF is being created.
l
@Matt Poloni Thanks for your input. What you have suggested does appear to be the case, that the #if is compiled first, and then the HTML is considered. In my example, it will check if the Item Type starts with any of those values, if it does, include it, and then there are two empty comments above and below it! I think what has confused me is that even in NS default Advanced PDF's, they use the same commenting (see attached: <!-- -->). Obviously this doesn't include any Freemarker tags which is why I was confused (and spent way too long trying to diagnose it!).
m
No worries, this happens to everyone who works with Advanced PDFs long enough. I personally only use the Freemarker comment syntax in my templates and I haven’t seen any issues from it. I really wish that NS would do the same.
r
I feel like this should be pinned.
👍 2
d
I think I was just experiencing the oddities of this behaviour just last week. I think I now know why. Thanks @Matt Poloni!
n
This is nice finding. Thanks for sharing it @Lee Hopper
l
@NickSuite You're welcome. I hope my hours of pain saves a few people from something similar!
keanu thanks 1