cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Room Reservation - Check if Date/Time Range is taken

Hi, 

I'm trying to resolve if a certain date range + time are already reserved.

- 2 date pickers for start and end date. 2 dropdown lists of 12hr times. 1 dropdown for room selection.

- I have 5 SharePoint lists columns.

  • TRAINING ROOM ( Single line of text)
  • START DATE and END DATE (Date and Time)
  • START TIME and END TIME (Choice).  

- I would like to display a text saying that a certain date/time is/are taken.

 

josefm2_2-1633119547905.png

josefm2_1-1633119404039.png

 

 

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
RusselThomas
Community Champion
Community Champion

Hi @josefm2 ,

So, first question I would ask is - you are already capturing datetime in your date field - why also then go and capture time in another field?  (This seems like an over-complication?)

Second question would be - the user experience could be frustrating, as they have to 'guess' what times are available.  Naturally they'll start with the date and time they want, then as they're blocked, they'll start by changing times, then dates - but as they're are increasingly blocked by conflicts this might get frustrating.

Would it not be better to present them with a calendar view showing currently booked times, or even better, just available times for them to choose from?

To answer your question though, essentially we have to assume that any overlap from a requested timeframe on an existing booking is considered a block.  Therefore we have to test both ends of the request to see if the start falls inside a booking, or the end falls inside a booking.  Only if neither do can we be sure that there are no conflicts.

So, the process of evaluation would be;

  1. Fetch all the bookings for the day of the request.
  2. For each booking, test whether the request start time falls after the booking start AND before the booking end OR whether the request end time falls before the booking end AND after the booking start.
  3. If any of those conditions are met, there is a conflict for that booking - if not, move onto the next booking and test again - repeat until you find a conflict or all bookings have been tested.

I don't know enough about your data construct to give you an exact solution, but in theory the logic of your behaviour formula might looks something like this;

 

Clear(collectConflicts);
ForAll(Filter(collectMySharePointBookings, bookingDate=requestDate),
   If(!IsEmpty(collectConflicts),
     If(
        (requestStart > bookingStart && requestStart < bookingEnd) OR
        (requestEnd < bookingEnd && requestEnd > bookingStart),
        Collect(collectConflicts, {Conflict: bookingName})
        )
     )
)

 

Behaviour formulas require an event to execute however, so you might want to put this on the OnChange: property of each dropdown/control.  We use a collection to contain the state of conflict within the ForAll() and an If() statement checking this collection each time to avoid unnecessary additional processing once a conflict is found.  The ForAll() will still run for each line, it just won't bother testing times once a conflict is found and should loop through the rest almost instantaneously.

As mentioned, this can make for a highly frustrating user experience, as they don't know which end of their booking is in conflict, so they have to keep choosing different times to see where they get lucky.  A better user experience might be to pop up a visual or calendar view for the day selected that shows either current bookings, or available slots for them to choose from.

[Edit]

Should probably also point out that the thing that will determine the visibility of your "Date already booked" warning would be whether collectConflicts is empty - so in the Visible: property of your warning text label, if the collection is empty, then the label is not visible - something like;

!IsEmpty(collectConflicts)

Hope this helps,

RT

View solution in original post

8 REPLIES 8
RusselThomas
Community Champion
Community Champion

Hi @josefm2 ,

So, first question I would ask is - you are already capturing datetime in your date field - why also then go and capture time in another field?  (This seems like an over-complication?)

Second question would be - the user experience could be frustrating, as they have to 'guess' what times are available.  Naturally they'll start with the date and time they want, then as they're blocked, they'll start by changing times, then dates - but as they're are increasingly blocked by conflicts this might get frustrating.

Would it not be better to present them with a calendar view showing currently booked times, or even better, just available times for them to choose from?

To answer your question though, essentially we have to assume that any overlap from a requested timeframe on an existing booking is considered a block.  Therefore we have to test both ends of the request to see if the start falls inside a booking, or the end falls inside a booking.  Only if neither do can we be sure that there are no conflicts.

So, the process of evaluation would be;

  1. Fetch all the bookings for the day of the request.
  2. For each booking, test whether the request start time falls after the booking start AND before the booking end OR whether the request end time falls before the booking end AND after the booking start.
  3. If any of those conditions are met, there is a conflict for that booking - if not, move onto the next booking and test again - repeat until you find a conflict or all bookings have been tested.

I don't know enough about your data construct to give you an exact solution, but in theory the logic of your behaviour formula might looks something like this;

 

Clear(collectConflicts);
ForAll(Filter(collectMySharePointBookings, bookingDate=requestDate),
   If(!IsEmpty(collectConflicts),
     If(
        (requestStart > bookingStart && requestStart < bookingEnd) OR
        (requestEnd < bookingEnd && requestEnd > bookingStart),
        Collect(collectConflicts, {Conflict: bookingName})
        )
     )
)

 

Behaviour formulas require an event to execute however, so you might want to put this on the OnChange: property of each dropdown/control.  We use a collection to contain the state of conflict within the ForAll() and an If() statement checking this collection each time to avoid unnecessary additional processing once a conflict is found.  The ForAll() will still run for each line, it just won't bother testing times once a conflict is found and should loop through the rest almost instantaneously.

As mentioned, this can make for a highly frustrating user experience, as they don't know which end of their booking is in conflict, so they have to keep choosing different times to see where they get lucky.  A better user experience might be to pop up a visual or calendar view for the day selected that shows either current bookings, or available slots for them to choose from.

[Edit]

Should probably also point out that the thing that will determine the visibility of your "Date already booked" warning would be whether collectConflicts is empty - so in the Visible: property of your warning text label, if the collection is empty, then the label is not visible - something like;

!IsEmpty(collectConflicts)

Hope this helps,

RT

Hi, thank you for the suggestion. I will take a look at it. For now, I have some clarification about what are you pertaining about the ff items. Which are my sharepoint columns(already booked dates) and datepicker values?

1. bookingDate

2. requestDate

3. requestStart

4. bookingStart

5. bookingEnd

6. requestEnd 

7. bookingName

 

Thank you.

RusselThomas
Community Champion
Community Champion

Hi @josefm2 ,

Thanks for marking the original solution, but it just occurred to me that  there is a gap in my thinking - if someone has a small booking set for the middle of the day, and someone else tries to book a whole day session, the start and end of the request won't land inside the existing booking so we won't detect the conflict.  I'm not sure if this situation is likely to occur in your instance, but to correct for this we just need to test in the opposite direction as well (meaning we need to test all bookings against the request, not just the request against all bookings).  This would look something like this;

Clear(collectConflicts);
ForAll(Filter(collectMySharePointBookings, bookingDate=requestDate),
   If(!IsEmpty(collectConflicts),
     If(
        ((requestStart > bookingStart && requestStart < bookingEnd) OR
        (requestEnd < bookingEnd && requestEnd > bookingStart)) OR  //request against booking
        
        ((bookingStart > requestStart && bookingStart < requestEnd) OR
        (bookingEnd < requestEnd && bookingEnd > requestStart )), //booking against request
        
        Collect(collectConflicts, {Conflict: bookingName})
        )
     )
)

 Kind regards,

RT

@RusselThomas thank you for the update.  followed your logic and came up with a modified version and it works. Validates a requested overlapping and within dates. The problem now is the time to the 'START DATE' and 'END DATE'.

 

Is it possible to join 2 sharepoint columns where:

1. A Date column(START/END DATE) is just a text field.

2. A Time column(START/END TIME) is a choice.

 

If I use just the START/END DATE column, the expression works.  It needs to find out if a certain date range is already taken or not. Now I'm trying to add the time to the START/END DATE and it prompts me with the error. If I encapsulate the START DATE and TIME with either value or text to make them the same, it returns saying the reverse. Now it says expecting TEXT value needed but if I set it as TEXT() it then it says it expects a number or value. 

 

ERROR:

josefm2_1-1633436866318.png

 

WORKING DATE VALIDATION:

josefm2_0-1633436745427.png

 

RusselThomas
Community Champion
Community Champion

Hi @josefm2 ,

Concat() used in this fashion will take all the rows in the source table and using the column you specify will concatenate all the values in that column with the separator you specify, resulting in a single string of concatenated values.  The separator you've chosen is 'START TIME'.Value so I'm not sure this is what you're looking for.

 

I believe your data constructs (Columns and types in SharePoint) are making your expressions overly complex.  You could resolve this with conversions and adding dates and times together, but I suspect your formulas might be almost unreadable by the time you're done.

 

I'm still unclear as to why you need to store Date in one column and Time in another? 

From what I've seen, much of this complexity can be resolved by simply adding a StartDateTime and EndDateTime column in SPO and setting them to allow Time.  Then your formula's will be relatively simple as you only have one value to reference and it will already be in DateTime format.  You can also extract DATE and TIME separately from this whenever you need to.

 

If you are being forced for some reason to use separate date and time columns, then I'd need to know what the format of your choices in the time column are to help you build the formula to add them with the date column.

The best I can offer is a guess that might help - eg: If they're in the format "08:30" then you could use Split() to pull out the hour and minute values, convert them to numbers using Value() and then plug them into a Time() function which will allow you to add them to the date;

 

'START DATE' + Time(Value(First(Split('START TIME'.Value, ":")).Result), Value(Last(Split('START TIME', ":")).Result), 0)

 

 This is however just a guess, and assumes 'START DATE' is actually a date format which, when converted to DateTime sets the time to 00:00:00 by default - which in turn allows us to add the Time component ourselves.

Hope this helps,

RT

Thanks so much @RusselThomas, this has helped me solve an issue I was fighting with for few days

just what I have been looking for, I like this part especially "as they don't know which end of their booking is in conflict, so they have to keep choosing different times to see where they get lucky.  A better user experience might be to pop up a visual"

 

I have done like you suggested and have set (start date + time) together, that goes the same for my (end date +time) these are date and time columns in SharePoint. 

 

My question is what would be the best way to show the user what is available to them for their selected dates and time. I was thinking a gallery that filters on your choices automatically as you change the dates and times on the calendar.

 

How would you go about this? 

 

 

RusselThomas
Community Champion
Community Champion

Hi @RossH85 ,

Probably about 50 different ways to skin that particular cat, but I guess the easiest would be a DatePicker control and a small gallery that shows the events from the day selected in 30min increments - that way you can just colour each increment based on whether there is a meeting scheduled during it or not.  Of course, a much easier way might be to just set the calendar up as a resource in Exchange and let people book through Outlook, but assuming you're set on using PowerApps, then that's probably how I'd do it. 🙂

If we consider there are 24 hours in a day, then there are 48 half-hours in a day, so the increment Gallery Items: might look like this;

 

AddColumns(Sequence(48,0), "Time", DateAdd(DateTimeValue(DatePicker1.SelectedDate), Value * 30, TimeUnit.Minutes))

 

Then just compare each iteration with anything in the calendar that starts <= it and ends >= it.
Hope this helps,

RT

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!   This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions in the Forums to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersNumber of SolutionsSuper UsersNumber of Solutions @anandm08  23 @WarrenBelz  31 @DBO_DV  10 @Amik  19 AmínAA 6 @mmbr1606  12 @rzuber  4 @happyume  7 @Giraldoj  3@ANB 6 (tie)   @SpongYe  6 (tie)     Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersSolutionsSuper UsersSolutions @anandm08  10@WarrenBelz 25 @DBO_DV  6@mmbr1606 14 @AmínAA 4 @Amik  12 @royg  3 @ANB  10 @AllanDeCastro  2 @SunilPashikanti  5 @Michaelfp  2 @FLMike  5 @eduardo_izzo  2   Meekou 2   @rzuber  2   @Velegandla  2     @PowerPlatform-P  2   @Micaiah  2     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 3:Community MembersSolutionsSuper UsersSolutionsPower Apps anandm0861WarrenBelz86DBO_DV25Amik66Michaelfp13mmbr160647Giraldoj13FLMike31AmínAA13SpongYe27     Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 4:Community MembersSolutionsSuper UsersSolutionsPower Apps DBO-DV21WarranBelz26Giraldoj7mmbr160618Muzammmil_0695067Amik14samfawzi_acml6FLMike12tzuber6ANB8   SunilPashikanti8

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (1,064)