Ask Your Question

Revision history [back]

You can use one of the script evaluators to do this. Here is a solution in Groovy:

import java.time.LocalDate

for (record in records) {
  try {
    // Get today's date
    LocalDate now = LocalDate.now()
    // Get the last day of last month
    LocalDate lastMonth = now.minusDays(now.getDayOfMonth())

    // Get the year and month for last month
    int year = lastMonth.getYear()
    int month = lastMonth.getMonthValue()

    // Initialize list for the days from last month
    record.value['daysLastMonth'] = []
    // Loop through the days for last month, appending the string representation
    // to the list
    for (int day = 1; day < lastMonth.lengthOfMonth() + 1; day++) {
      record.value['daysLastMonth'].add(sprintf('%04d%02d%02d', year, month, day))
    }

    output.write(record)
  } catch (e) {
    log.error(e.toString(), e)
    error.write(record, e.toString())
  }
}