cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
kinghnvn
Helper V
Helper V

Limit number of bookings

Hi all,

 

I have a Book button to book a desk.

How to limit number of bookings (total 1 or total 2) during the day?

kinghnvn_0-1640055560172.png

@StalinPonnusamy 

 

7 REPLIES 7
AJ_Z
Super User
Super User

I would do this utilising DisplayMode for the button, a Label for user journey and a countrows with a filter.
Step One: change the button's DisplayMode to If(CountRows(Filter(Datasource,User.Email = User().Email && RelatedDate = Today()))>=2, DisplayMode.Disabled,DisplayMode.Edit)

Step Two: change the label's Visible property to: CountRows(Filter(Datasource,User.Email = User().Email && RelatedDate = Today()))>=2

Step Three: change the label's text to something like. "You cannot Book more than Two Desks in one Day"

Ensure you tweak my formula to matchup with your datasource  an situation. everything in red probably needs to be changed the blue part for Today() may need to change if they are using a dataselector to book for the future.


If you need more help on how to apply this to your circumstance please provide the name of the Datasource and the column name / column type referencing who booked it. Then also let me know how they are picking the day is it a DataSelector or always Today()



Signature:


If you appreciated my comments/responses please be sure to Like/Kudo them it really does make me smile 🙂 !
Link to the Power Platform Professionals United Kingdom User Group:

https://powerusers.microsoft.com/t5/Power-Platform-Professionals/gh-p/PowerPlatformProfessionalsUnit...

I'm using DisplayMode for the Button as below.

How to combine your code?

 

If(
!IsBlank(
LookUp(
DeskBooking,
Employee.Email = UserInfo.Email && MySlotTime
)
),
DisplayMode.Disabled,
!IsBlank(
LookUp(
DeskBooking,
MySlotTime && Title = MainGallery.Selected.Title
)
),
DisplayMode.Disabled
)

Hi @kinghnvn 

 

First, you can combine your current code like

If(
!IsBlank(LookUp(DeskBooking,Employee.Email = UserInfo.Email && MySlotTime)) ||
!IsBlank(LookUp(DeskBooking,MySlotTime && Title = MainGallery.Selected.Title)),
DisplayMode.Disabled,DisplayMode.Edit
)

 

Second, You are using Calander control which has a Date Range so Changing your current display mode may be challenging since we need to loop through the selected dates to check each date.

 

So, We need to validate this logic on the "OnSelect" of the Book button.

 

Logic concept

  • Declare a local variable to false
  • Loop through the Calander Dates
  • Get each single date
  • Get the Booking count for each day
  • If any one of the days is more than 2 then set the variable to true
  • Finally, verify No days has more than 2
    • If Yes through the message or display Label
    • If No then Patch or Save
UpdateContext({IsMorethan2Bookings : false});

ForAll(DateDiff(Calander1.StartDate, Calander1.EndDate),
If(CountRows(
Filter(OfficeBooking, 
EmployeePerson.Email = UserInfo.Email && BookingDate = DateAdd(Calander1.StartDate, ThisRecord.Value,Days)
)) >= 2,UpdateContext({IsMorethan2Bookings : true});
) //If
); //ForAll

If(IsMorethan2Bookings, Notify("You can't book more than two desks in single day"),
Patch(.....)
)


Thanks,
Stalin - Learn To Illuminate

  

AJ_Z
Super User
Super User

Is this a displaymode if statement for a different reason or for the same issue. if it is for a different thing i know just where to insert our bit but if you are attempting to resolve the same thing we will likely just need to replace it 🙂 . Also is MySlotTime a column in the datasource and is it date only or date and time if so or is it some other data type. This will help me understand the situation so we can adapt my suggestion 🙂

 



Signature:


If you appreciated my comments/responses please be sure to Like/Kudo them it really does make me smile 🙂 !
Link to the Power Platform Professionals United Kingdom User Group:

https://powerusers.microsoft.com/t5/Power-Platform-Professionals/gh-p/PowerPlatformProfessionalsUnit...

AJ_Z
Super User
Super User

I just noticed that @StalinPonnusamy has popped in to offer assistance reply @AJ_Z  to me if you still need me 🙂 . But i am sure he is able to assist.



Signature:


If you appreciated my comments/responses please be sure to Like/Kudo them it really does make me smile 🙂 !
Link to the Power Platform Professionals United Kingdom User Group:

https://powerusers.microsoft.com/t5/Power-Platform-Professionals/gh-p/PowerPlatformProfessionalsUnit...

For First, you can combine your current code like -> Yes, I'm using the same the code

 

If
(
!IsBlank(LookUp(DeskBooking,Employee.Email = UserInfo.Email && MySlotTime)), DisplayMode.Disabled,
!IsBlank(LookUp(DeskBooking,MySlotTime && Title = MainGallery.Selected.Title)), DisplayMode.Disabled
)

 

For Second, I have tried to use the code but it's not working

 

Behavior function in a non-behavior property. You can't use this propert to change values elsewhere in the app.

Delegation warning. The highlighted part of this formula might not work correctly on large data sets. The "CountRows" operation is not supported by this connector.
The function 'If' has some invalid arguments.

--

 

The Book button / Visible:

 

UpdateContext({IsMorethan2Bookings : false});
ForAll(DateDiff(Calendar_1.StartDate, Calendar_1.EndDate),
If(CountRows(
Filter(OfficeBooking_1,
Employee.Email = UserInfo.Email && FromDate = DateAdd(Calendar_1.StartDate, ThisRecord.Value,Days)
)) >= 2,UpdateContext({IsMorethan2Bookings : true});
) //If
); //ForAll

If(IsMorethan2Bookings, Notify("You can't book more than two desks in single day"),
Patch(.....)
)

 

kinghnvn_0-1640242610182.pngkinghnvn_1-1640242687959.png

 

Hi @AJ_Z 

 

I just noticed that @StalinPonnusamy has popped in to offer assistance reply @AJ_Z to me if you still need me 🙂 . But i am sure he is able to assist. -> My question is open for everyone ^^. thank you so much, I'm still need your help.

 

Step Two: change the label's Visible property to: CountRows(Filter(Datasource,User.Email = User().Email && RelatedDate Today()))>=2

-> I have tried your code as below

 

CountRows
(Filter
(Datasource,
Employee.Email = UserInfo.Email &&
DateValue(Text(selectedEndDate,DateTimeFormat.ShortDate)) = FromDate)) < 1

 

but I'm getting the message:

 

Delegation warning. The highlighted part of this formula might not work correctly on large date sets. The "CountRows" operation is not supported by this connector.

Helpful resources

Announcements
Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on August 17, 2022 at 8am PDT.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Users online (1,911)