I have been altering the totals of Sales Orders mi...
# ask-stanley-ai
a
I have been altering the totals of Sales Orders mid-render by doing simple arithmetic: assign a freemarker variable and set to 0, add the amount on each line to it, but only conditionally. Do this in separate variables for the subtotal and the tax total (only tax lines get added to the tax total, and only non-tax lines get added to the subtotal). At the end assign the grand total to be the subtotal variable plus the tax total variable. Render the variables' values instead of what's on the Sales Order record object. This allows us to exclude certain lines from the transaction and make the totals at the end add up to the amount they would with those lines removed. The lines being removed are those which have their "Closed" column set to Yes. Is there a better way to do this specific thing (excluding Closed lines from the PDF and its total amounts), like a Preference that I just couldn't find?
c
AI generated answer (using internal Slack threads):
Based on the conversations, it seems that you are already on the right track with your current approach. Using Freemarker to conditionally sum up the line items and then rendering those variables is a common practice in NetSuite's Advanced PDF/HTML Templates. However, there is no built-in preference in NetSuite to exclude closed lines from the PDF and its total amounts. You would need to continue using your current method or consider a more advanced approach such as creating a custom SuiteScript beforeLoad script that manipulates the data before it is sent to the template. This would involve creating a custom field, calculating the totals there, and then referencing that field in your template. Here is a sample code snippet for your reference:
Copy code
freemarker
<#assign subtotal = 0>
<#assign taxtotal = 0>
<#list record.item as line>
  <#if line.closed != "Yes">
    <#if line.taxcode == "Non-Taxable">
      <#assign subtotal += line.amount>
    <#else>
      <#assign taxtotal += line.amount>
    </#if>
  </#if>
</#list>
<#assign grandtotal = subtotal + taxtotal>
Remember to replace the field names with the actual field names in your record. ****** 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.831179261
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.825231194
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.824970186
Please provide your feedback on this answer.
a
I tried the beforeload way and there were some use cases where it didn't get the request parameters or it dropped something or other, so this might be the best way.