AnsweredAssumed Answered

How do I get the last date in a month for a given date?

Question asked by mallikarjun.ratala563207 on Apr 10, 2017
Latest reply on Apr 24, 2018 by indrajeet.jain888465

How do I get the last date in a month for a given date? 

eg: input is 5/4/2017 (dd/MM/yyyy format) output should be 30/4/2017

 

I've tried ( in local atom as well as in "Test Atom Cloud" the below script  in Boomi, but I get errors in two different scenarios:

 

When Input(inputDate) is set as Date/Time:

Test execution of TestProcessNoDate completed with errors. Embedded message: [Function: MF_GetLastDateOfMonth, Scripting (Step 2)]: Error parsing DATETIME input value '05/04/2017' for parameter inputDate.; Caused by: Unparseable date: "05/04/2017"

 

When Input(inputDateis set as Character:

 Test execution of TestProcessNoDate completed with errors. Embedded message: [Function: MF_GetLastDateOfMonth, Scripting (Step 2)]: Error executing custom script: No signature of method: java.util.GregorianCalendar.setTime() is applicable for argument types: (java.lang.String) values: {"05/04/2017"} (in groovy script); Caused by: No signature of method: java.util.GregorianCalendar.setTime() is applicable for argument types: (java.lang.String) values: {"05/04/2017"} (in groovy script); Caused by: No signature of method: java.util.GregorianCalendar.setTime() is applicable for argument types: (java.lang.String) values: {"05/04/2017"}

 

 

=========Groovy script=============

import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.GregorianCalendar;

SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Calendar calendar = Calendar.getInstance();
calendar.setTime(inputDate);

calendar.add(Calendar.MONTH, 1);
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.add(Calendar.DATE, -1);

String outputDate= sdf.format(calendar.getTime());

=======================================

 

How ever, this script runs successfully in Eclipse. 

 

Appreciate, if you can please point out

1. What is the issue with above script?

2. Since the lack of testing scripts in Boomi as functions, what is the best method to do unit tests for scripts ( through eclipse?)

3. How does Boomi import the various classes? Does it already have them in lib (or when running via local atom, doe they need to be added?)?

 

Thanks for your inputs

Mallik

Outcomes