I am trying to write a script in Netsuite and trying to figure out how I can accomplish my goal. I am trying to create a past due reminder email script. First of all, I think this would be best setup as a Scheduled script but let me know if I am thinking about this wrong. I also started to mock up some pseudocode for what I want it to do. I created some custom fields to set the date when the email was last sent so that customers don't get spammed constantly. We want it to wait a 8 days before being able to send to that customer. I also created a checkbox to be able to exclude some customers.
function EmailStatement { DaysSinceLastEmailed = getDays(getDaysSinceLastEmailed, current) if(daysoverdue >= 11 && balance > 1 && DaysSinceLastEmailed >= 8 && ExcludeReminder == false ) { if(type == company && contactRole == Accountant) { grab accounting email } else { grab the regular email } set title of email to "Your Account is Past Due" set message body to "hardcoded message" attach statement with A/R detailed Aging send! } } function getDays(date1, date2) { // The number of milliseconds in one day var ONE_DAY = 1000 * 60 * 60 * 24 // Convert both dates to milliseconds var date1_ms = date1.getTime() var date2_ms = date2.getTime() // Calculate the difference in milliseconds var difference_ms = Math.abs(date1_ms - date2_ms) // Convert back to days and return return Math.round(difference_ms/ONE_DAY) } My second question is, should I create another function that actually creates the email body and call it from the email statement function?Third, am I on the right track? Do I need to create a customer object when doing a scheduled script?Any help is very much appreciated!