Compare a combination of different attributes

Hi guys, I'm fairly new to Mendix and i'd like to know how i can compare a combination of attribute values, for example: Now i've created a form where the user can fill in all these attributes. I want to prevent that the same room on the same date and in between the start-end time can be filled in the form again.  
3 answers

This would be one way to do it.

Your microflow needs two parameters. One would be reservation (which you have), and I'm assuming this is a new reservation that someone is trying to place. The second parameter would be Room (the room you are trying to place the reservation for). To do this, you would need two dataviews on the page that this button is in. I would use room as the caller of the page and the new reservation inside of it. Then you can place this button inside the dataview for reservation and it will allow you to pass two parameters.

Another way to do it, is use a retrieve by association as the first activity and retrieve the room from the reservation (if this association is set already)


The first activity would be a retrieve from database where you would have constraints that will match the date, start, and end time of the of the reservation that you passed as a parameter. 

Here is the xpath that stefan gave above. I added some date xpath functions to compare the day, month, and year. The datepicker widget also stores a time, so if you did an equal on this attribute, most likely the date and time won't match.

[MyFirstModule.Reservation_Room = $Room]
[day-from-dateTime(date) = day-from-dateTime($Reservation/date)]
[month-from-dateTime(date) = month-from-dateTime($Reservation/date)]
[year-from-dateTime(date) = year-from-dateTime($Reservation/date)]
[start_time <= $Reservation/end_time]
[end_time >= $Reservation/start_time]


Then as Stefan mentioned, this retrieve will return a list if there is any overlap, you can use an exclusive split to check if its empty or not using the expression.

$ReservationList = empty

So if the exclusive split is true, then there is no overlap and you can use the commit activity to commit your reservation. If its false then add whatever logic you want.


I also want to add that this will only work if you are associating your reservations to your rooms correctly. If not, then the list will always return empty.


Hope this helps!


Create a microflow where you do the checks if the new reservation does not clash with existing reservations. Use a parameter to pass the new reservation to the microflow. Then in the microflow you can do retrieves on the existing database to see if the reservation is possible. So do a retrieve of all the reservation on that day for that room and then iterate over those to do the checking if the timeslot is still available. That last one can be quite complex though.




See the forum question here:

I think I already gave some hints to a classmate :)



Do a retrieve on your reservations like:

[Date = $Reservation/date and Start < $Reservation.end  and End > $Reservation.Start] this will give a list with all your reservation which overlap. So if it is empty it is available.

If you need to have reservations which can span days, just use a start and a end as datetime.