web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to make powerapps ...
Power Apps
Answered

How to make powerapps prevent user from requesting a leave that already booked by him?

(0) ShareShare
ReportReport
Posted on by 16

I need your help to prevent powerapps submitting the days of a new leave request if it is already booked by the employee

without using the built-in leave template ... the problem is my app not saving the specific days of the leave only the numbers of the days to subtract it from the quota,,,

 

Please any help would be highly appreciated

Categories:
  • Pstork1 Profile Picture
    69,661 Most Valuable Professional on at

    I don't see any way to do this unless you store at least the starting date of the leave in your data source in addition to the number of days. Without storing a specific date you have nothing you can check new entries against.

  • v-xida-msft Profile Picture
    Microsoft Employee on at

    Hi @Mays ,

    Could you please share a bit more about your scenario?

    Could you please show more details about the data source you used to store the submitted Leave Request?

     

    I assume that you have added corresponding columns (StartDate, EndDate and Requester) in your data source to store the New Leave Request Detail.

    The StartDate column is used to store the Start date of the new Leave request, the EndDate column is used to store the End date of the new Leave request, the Requester column used to store the display name of the user who submit this Leave Request.

     

    If you want to prevent powerapps submitting the days of a new leave request if it is already booked by the employee, I have made a test on my side, please take a try with the following workaround:

    Set the OnSelect property of the "Submit" button to following:

    If(
     !IsBlank( /* <-- Check if the same Leave Request submitted from current sign in user is already existed in your data source */ 
    LookUp('YourDataSource', StartDate = StartDatePicker.SelectedDate && EndDate = EndDatePicker.SelectedDate && Requester = User().FullName)
    ), Notify("Your have submitted same Leave Request, please do not submit repeatedly!", NotificationType.Error), Patch( /* <-- Submit new Leave Request */ 'YourDataSource', Defaults('YourDataSource'), { StartDate: StartDatePicker.SelectedDate, EndDate: EndDatePicker.SelectedDate, Requester: User().FullName,
    ... } ) )

    Please take a try with above solution, then check if the issue is solved.

    Note: On your side, you could search the submitted Leave Requests within your data source based on the new Leave Request before submitting, check if there is already a record submitted from you existed in your data source.

     

    More details about the LookUp function and Patch function, please check the following article:

    LookUp function, Patch function

     

    Best regards,

  • Mays Profile Picture
    16 on at

    Thank you @Pstork1 , @v-xida-msft  for your reply ,I already did this in my sharepoint list as attached ,

    but for example if employee request a leave for the days from 10-Jun to 13-Jun the datasource will capture the start,end and the number of days ...that mean if this employee by mistake submitted a new leave request for the days for example from 12-Jun to 15-Jun ,

    In this case the app should through an error "you already have a leave for the day 12 and 13 of Jun" (it is already booked)

     

    I hope you get my point and sorry if i didn't explain it clearly

    leaveRequest.PNG
  • Mays Profile Picture
    16 on at

    @v-xida-msft  I will try this solution and get back to you very soon ... Thanks

  • v-xida-msft Profile Picture
    Microsoft Employee on at

    Hi @Mays ,

    Have you solved your problem?

     

    If you have solved your problem, please go ahead to click "Accept as Solution" to identify this thread has been solved.

     

    If you have any questions when using formulas in PowerApps, please feel free to reply here.

     

    Best regards,

  • Mays Profile Picture
    16 on at

    Hi @v-xida-msft  ,,, I changed it slightly to fit with my datasource , I requested leaves from 14/06 to 16/06 then I tryed to apply the days from 15/06 to 17/06 that should give an error for the days 15 and 16 but the app saved it successfuly !!

    If(
     !IsBlank( /* <-- Check if the same Leave Request submitted from current sign in user is already existed in your data source */ 
     LookUp(LeaveList, From = DataCardValue19.SelectedDate && To = DataCardValue20.SelectedDate && DataCardValue4.Selected.Email = Leave_x002d_Employee.Email)
     ),
     Notify("Your have submitted same Leave Request, please do not submit repeatedly!", NotificationType.Error),
     SubmitForm(LeaveDetailsForm)
    )
    Capture0.PNG
    Capture2.PNG
    Capture1.PNG
  • Pstork1 Profile Picture
    69,661 Most Valuable Professional on at

    YOur logic only checks whether it has the same start and end dates.  I think you need to change the '=' in your test to '>='  for the start and '<=' for the end.  Otherwise you won't catch dates that fall in the middle.

  • Verified answer
    v-xida-msft Profile Picture
    Microsoft Employee on at

    Hi @Mays ,

    Based on the issue that you mentioned, I think this issue may be related to the '=' operator within the formula I provided above.

     

    Please consider modify your formula as below:

    If(
     !IsBlank( /* <-- Check if the same Leave Request submitted from current sign in user is already existed in your data source */ 
     LookUp(LeaveList, From <= DataCardValue19.SelectedDate && To <= DataCardValue20.SelectedDate && DataCardValue4.Selected.Email = Leave_x002d_Employee.Email)
     ),
     Notify("The days from " & DataCardValue19.SelectedDate & " to " & LookUp(LeaveList, From <= DataCardValue19.SelectedDate && To <= DataCardValue20.SelectedDate && DataCardValue4.Selected.Email = Leave_x002d_Employee.Email).To & " has been booked!", NotificationType.Error),
     SubmitForm(LeaveDetailsForm)
    )

    Please consider take a try with above solution, then check if the issue is solved.

     

    Best regards,

  • Mays Profile Picture
    16 on at

    Thank you very much @v-xida-msft  & @Pstork1  I could solve my probelm because of your help

    ,Much appreciated 

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi all, 

    Despite I try to follow the guidelines provided in such conversation, no way for me to reach the expected result.

    My goal is to configue the same solution as describe on this post (in my case I ama using as datasource an excel file).
    The porblem is anytime I copy/paste the code provided by @v-xida-msft  and despite I modify the informartion as expected, I have still some error in the formula


    Matthieu1_0-1615820905797.png

    Matthieu1_1-1615820962342.png

    Is there any chance to help to solve this problem?

     

    Thanks in advance,

     

    Matthieu

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 397 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 354

#3
WarrenBelz Profile Picture

WarrenBelz 232 Most Valuable Professional

Last 30 days Overall leaderboard