Latest of three dates in entity

1
Hi all,  In an entity I have three dates that are all different events. I have a report that needs to show the list of objects in order of these dates.  I am wondering what the best way to do this is. I currently have a 4th date time attribute in the entity which i've called NextDate. I've sorted a datagrid by this date, and now just need to populate the attribute.  My current thinking is that in microflow do a calculation that works out which of the three dates is the next date in the future. I know how i'd do this if it were three different objects, but i'm not sure how to do this when the three dates are in the same object.  Another ways i've thought of, is having these dates in seperate  entities linked 1-1 to the parent and treat them as three objects.  Does anyone have any thoughts on the best way to go about this Many thanks,     EDIT: Thank you everyone for your inputs!
asked
5 answers
9

Hi Garion,

 

In a microflow you could use a non persistant entity with a date attribute to store your event dates in (only create the object if the date is in the future) and add them to a list of that entity. If the list only consists of future dates, sort your list ascending on the date attribute. The head of the list will be your next date in the future. You should store this date in the 4th date attribute.

 

Hope this will help.

 

Regards,

Thomas 

answered
2

Do you need to show the last date relative to each other? Or do you need to show the date closest to now?

If it is the first, you could do your 4th date calculation in a before commit microflow but this will not work for the second logic.

answered
1

Sounds like you need to use the ChangeObject activity to give attribute NextDate this value:

if ($MyObject/date1 > [%EndOfCurrentDay%]
    and $MyObject/date1 < $MyObject/date2
    and $MyObject/date1 < $MyObject/date3)
    then $MyObject/date1
    else if ($MyObject/date2 > [%EndOfCurrentDay%]
             and $MyObject/date2 < $MyObject/date3)
           then $MyObject/date2
           else if $MyObject/date3 > [%EndOfCurrentDay%]

                   then $MyObject/date3
                   else somedefaultdate

answered
0

I would create 4 associations: three of them would be 1-1 as you suggest, one for each event (all the same entity). Then I'd also add another 1-*, which could contain all three of the events. Then you can retrieve an individual event easily, and you can also retrieve the list of events in any order you need them.

answered
0

Does the datagrid need to be sorted by this 4th date? If not, seems like you would need to use a calculated attribute.

https://docs.mendix.com/refguide/attributes

 

If you change your attribute from stored to calculated you can choose a microflow to run every time this attribute is displayed on the page. The microflow can do the the calculation described by Tim and return that date to be shown.

 

If your datagrid needs to be sorted by this date, then I suggest running a Daily scheduled event that does the calculation that Tim described. Since the calculation is relevant to current date time, then you would need to update your data daily. 

answered