Ynias
Ynias

Reputation: 1

How to prevent double bookings in PowerApps

Situation: I'm developing an app where you can book stations on a chosen date and time with durations of 1, 2 or 4 hours. UI of the app.

Question: What's the best way to prevent double bookings? They may also not overlap.

Important tables:

  1. Booking (BookingStation, Begin, End, Duration, Owner) View table with data
  2. Duration (Time, Minutes, Length) View table with data
  3. Station (Name, Number) View table with data

The code in 'items' of the gallery showing the stations:

SortByColumns(
Filter(
    Stations;
    Not(
        Name in Filter(
            Bookings;
            (Begin >= VarBeginDateTime && End <= varEndDateTime && Name <> BookingStation.Name);
            (Begin <= VarBeginDateTime && End <= varEndDateTime && Name <> BookingStation.Name);
            (Begin >= VarBeginDateTime && Begin <= varEndDateTime && End >= varEndDateTime && Name <> BookingStation.Name);
            (Begin <= VarBeginDateTime && End >= varEndDateTime && Name <> BookingStation.Name)
        ).Name
    )
);
"cr8fc_number";
Ascending
)

OnSelect code from button Book:

 Set(varNumDuration; varDuration);;

// Make booking
Patch(Bookings; Defaults(Bookings); 
{Begin: VarBeginDateTime}; 
{End: varEndDateTime}; 
{BookingStation: varStationSelected};
{Duration: varDuration});;

// Send mail
Office365Outlook.SendEmailV2("[email protected]";"Confirmation booking "&varStationSelectedText;" 
Dear "& varMyDetails.FullName & "," & "<br><br>These are your booking details:" &
"<br><br>Start: "&VarBeginDateTime & "<br> End: "&varEndDateTime& "<br> Duration: "&varDurationText& "<br> Station: "&varStationSelectedText 
& "<br><br> Kind regards, <br> Booking station app");;

// Next screen
Navigate(ConfirmationScreen);;

Upvotes: 0

Views: 1217

Answers (1)

Iona Varga
Iona Varga

Reputation: 547

This is not as much a PowerApps question as it is a logic question.

Say you have an appointment from 1 PM to 2 PM. You then need to check for a few things:

  1. Is the starting time of my new appointment greater or equal to the ending time of an existing appointment.
  2. Is the ending time of my new appointment smaller or equal to the starting time of my existing appointment.

If this is the case, you have an open slot and know its safe to book.

Another way of doing it, for example, is to filter your bookings towards the day and do a CountRows to check if there is already a booking during the timeslot that is selected.

G'luck

Upvotes: 0

Related Questions