1
0
-1

Hi,

Is it possible to have a calculation column in a data list in the community version?

For example I need to have a column age which automatically displays calculated age based on birth date column every time the data list is opened.

    CommentAdd your comment...

    1 answer

    1.  
      1
      0
      -1

      Hi genti,

      Try out this sample app below. Check out the script in the Bean Shell Datalist Formatter for the "Calculated Age" datalist column.
      Feel free to modify the code to match your exact requirement.

      APP_beanshellformatter_calculation-SAMPLE.jwa


      Code snippet:

      import java.text.ParseException;
      import java.text.SimpleDateFormat;
      import java.util.Date;
      import java.util.Calendar;
       
      SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
      try {
          Date birthDate = formatter.parse(value);
          Calendar birthDateCal = Calendar.getInstance();
          birthDateCal.setTime(birthDate);
          
          Date currentDate = new Date();
          Calendar currentDateCal = Calendar.getInstance();
           
          return (currentDateCal.get(Calendar.YEAR) - birthDateCal.get(Calendar.YEAR)).toString();
      } catch (ParseException e) {
          e.printStackTrace();
      }
      1. genti

        Hi, In the sample the data list is empty, no columns. In the userview when I click on properties of Manage Test nothing happens, it does not open.

        I am using joget 6

      2. Chris Angel

        I'm currently using Joget DX. If its possible for you, I think its best to upgrade. Comes with more features and crucial security patches.

        On another note, you also must be using Java 8 or above in order for the script to work. Just use a Bean Shell Formatter on your datalist column that has the date values, and paste in the script above.

      3. genti

        Hi,

        Same on joget DX and I am using java 8



      4. Chris Angel

        Hmm this is strange. Try importing the app to another Joget instance to rule out any issues with the sample app above.

        On the other hand, I found this guide here that you can also refer to, so you can also insert the script into your own app. 

        Compare Date Column Value with Current Date

      CommentAdd your comment...