Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In this case, we want to return the status "Expired" or "Active" based on the date value in the datalist compared to the actual date.

Edit the datalist column where you want to return the status and select Bean Shell Formatter to enter the code below(Refer to Figure 2).

Image Added

Figure 1


Image Added

Figure 2Image Removed


Code Block
titleSQL
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
try {
    Date date = formatter.parse(value);
    Calendar cal = Calendar.getInstance();
    if (date.before(cal.getTime())) {
        return "Expired";
    } else {
        return "Active";
    }
} catch (ParseException e) {
    e.printStackTrace();
}

...