Power Apps - Restrict duplicate bookings in a booking system developed with model driven app

1.1k views Asked by At

We are doing a POC on Power Apps with a trial version and we have developed a room booking app in Model-Driven App under Power Apps. If the User has booked any room and another user tries to book a room for the same date, it should not allow. It is an essential validation for any booking system but unable to find a way to achieve the same in Power Apps

For example: - If a user booked a room in Delhi from 1st to 5th Jan. Other users should not be allowed to book this room for the above dates. Another user books the same room for 1st Jan to 4th Jan then it should not allow but we have not found any feature in the model-driven app to restrict the entry of this record.

Does anyone know how to proceed?

enter image description here

1

There are 1 answers

4
Robbert On

This is a high level answer given the lack of specifics in your question. When the user selects a time, you should add the following to your OnSelect event of the gallery or button (whatever you use to let the user select the room).

//Refresh the datasource
Refresh(YourDatasource);

// Filter the data source looking for other events in this room
UpdateContext({RoomEvents,Filter(YourDataSource, RoomID=selectedRoom,Date=SelectedDate)});

// check if there are any items in RoomEvents. If there are, then the room is no longer available
if(RowCount(RoomEvents)>0,Notify("This room is no longer available",NotificationType.Error))

Again, this high level, but should get you going in the right direction. You should do something similar when displaying the list of rooms in the first place, filtering out rooms that are not available.