0

I am VERY new to Freemarker. Apparently, it is the template model of choice in NetSuite. I am tasked with updating an email template to display a line of text that includes the last business day of the month.

I see how to display the field in documentation that I have found and here is my code for that.

<#assign aDateTime = .now>
<#assign aDate = aDateTime?date>
<span>PLEASE EXPEDITE ORDER PROCESSING AND SHIP OVERNIGHT TO GUARANTEE DELIVERY BY EOD 
THE LAST BUSINESS DAY OF THE MONTH ${aDate}</span>

My question, since I clueless here, is how to display the last business day of the month?

EDITED TO ADD: I have found that the add ins for Freemarker date manipulation can be of some assistance here (based on another thread here). The issue is getting the right logic down to show the date. Here is an example of subtracting 18 days from a certain date:

${(mydate?long - 18 * 86400000)?number_to_date?string("yyyy-MM-dd")}

So I know there is a way to do what I am trying to do with this, but I just can't wrap my head around it.

Any and all assistance would be greatly appreciated.

Thanks.

Finnster
  • 87
  • 3
  • 16

2 Answers2

1

There are a couple of approaches here depending on how the template is being called. If you are using this as a standard template triggered on a record (transaction) then you need to get the last business day of the month value into a custom field on the record. You could do that by creating a custom record of months that has a start and end date and a last business day. Then you make your last business day field a Custom Body Date Field Non-Stored Defaulted from a saved search

The saved search uses either today's date or some date from the transaction to lookup the date's month's last business day. Of course if that is based on the transaction's date then you can set the value with a script.

If you can set it with a script the custom record solution still works. What I've done in the past though is build a function that can do business date calculations based on the account's location (US or Australia) and the observed statutory holidays.

Both approaches require occasional updates. The function of course could also be used to generate upcoming last business dates.

A couple of examples of business day calculations are in my github repo for Netsuite things. calculateShippingDates and calcNSWBusinessDays are examples of generating calculating spans of business days. calculateShippingDates actually has a last business day of month calc.

HTH

bknights
  • 14,408
  • 2
  • 18
  • 31
  • The template is a standard email triggered by a transaction's workflow. So, essentially you are saying that a simple script tied to the email template to fill that value is the way to go about doing this? I will have to do some more digging as I am not sure how to do that. The javascript I THINK I can make work, but tying the script to the email template and into the FreeMarker field is beyond me right now. Thank you very much for your reply. – Finnster Jul 17 '17 at 17:41
  • If you are just doing the standard template then use the custom record approach. You can easily fill in 5 years of last business days with a csv import and then go to SuiteAnswers topic 61574 for how to set up the custom field and custom search. – bknights Jul 17 '17 at 19:24
  • Ok. Thank you. However, I think I need to script this as I need to make it so that maintenance is almost at a zero percent, so the CSV file combined with the record may not be the best approach. I sincerely do appreciate your help on this. Thank you again. – Finnster Jul 18 '17 at 12:31
  • No worries. I'd recommend starting out with the custom records anyway though -- You can concentrate on the immediate need. FWIW I added a reference to a github repo that already does business day calcs. Feel free to adapt it to your needs. – bknights Jul 18 '17 at 15:48
  • Well ... I didn't need to script it. Check out the Freemarker solution I added. – Finnster Jul 18 '17 at 15:49
  • As long as Memorial Day, Thanksgiving, New Year's Eve and Easter are not holidays for your business you should be ok with just the weekday test. – bknights Jul 18 '17 at 16:47
  • Yeah ... I told my boss I was not accounting for holidays and that since I got THIS far, he had to be good with it. Besides, the boss is on vaca this week. I do appreciate your help though. Thank you! – Finnster Jul 18 '17 at 16:55
0

I figured this out. I used a thread showing how javascript picked the last day of the month (link here) and then converted that code to Freemarker. Here is the Freemarker code snippet:

<#assign aMonth = .now?string("M")>
<#assign aNewMonth = aMonth?number>
<#assign aYear = .now?string("yyyy")>
<#assign aDay = 0>
<#assign aNewDate = "" + (aNewMonth + 1) + "/" + aDay + "/" + aYear>
<#assign aLastDay = aNewDate?date>
MONTH: ${aNewMonth}<br />
YEAR: ${aYear}<br />
${aLastDay?string.full}<br />

This is the LAST day of the month. I do some if then else logic to determine if the string is a Saturday or Sunday and then print out the correct last business day of the month.

Finnster
  • 87
  • 3
  • 16