Reputation: 183
I'm using Groovy(1.5) in Boomi to capture the last day of the previous month, and I've been mixing some things I found via Google:
import java.util.Properties;
import java.io.InputStream;
for( int i = 0; i < dataContext.getDataCount(); i++ ) {
InputStream is = dataContext.getStream(i);
Properties props = dataContext.getProperties(i);
dataContext.storeStream(is, props);
}
var dt = new Date();
dt.setDate(1);
dt.setHours(-1);
props.setProperty("document.dynamic.userdefined.StartDate",dt);
But I'm being met with the following error:
No signature of method: com.sun.script.groovy.GroovyScriptEngine.var() is applicable for argument types: (java.util.Date) values: {Thu Feb 25 16:09:33 UTC 2021} (in groovy script);
Caused by: No signature of method: com.sun.script.groovy.GroovyScriptEngine.var() is applicable for argument types: (java.util.Date) values: {Thu Feb 25 16:09:33 UTC 2021}
Upvotes: 1
Views: 1537
Reputation: 63
The below example shows how to get the last day of the previous month and format as:
.
The main trick is subtracting the Calendar.DAY_OF_MONTH from the current date which will always provide the last day of the previous month.
.
import java.text.SimpleDateFormat;
def date = new Date();
date = date.minus(date.getAt(Calendar.DAY_OF_MONTH));
def ddmmyyyyDateFormat = new SimpleDateFormat("dd-MM-yyyy")
def dayShortNameDateFormat = new SimpleDateFormat("E");
def dayFullNameDateFormat = new SimpleDateFormat("EEEE");
println "Date of last day of previous month: " + ddmmyyyyDateFormat.format(date);
println "Last day of previous month: " + date.getAt(Calendar.DAY_OF_MONTH);
println "Short name of day: " + dayShortNameDateFormat.format(date);
println "Full name of day: " + dayFullNameDateFormat.format(date);
Upvotes: 0
Reputation: 61
var
is a JavaScript reserved keyword. Two ways to fix this error:
Use JavaScript as Language:
Replace var
with def
:
def dt = new Date();
dt.setDate(1);
dt.setHours(-1);
Upvotes: 0