cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Mays
Helper I
Helper I

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

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

1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

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,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

13 REPLIES 13
Pstork1
Dual Super User
Dual Super User

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.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Join me at 365EduCon in Chicago on Sept. 26-30 where I'll be presenting on the Power Platform!
v-xida-msft
Community Support
Community Support

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,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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

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

v-xida-msft
Community Support
Community Support

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,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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)
)
Pstork1
Dual Super User
Dual Super User

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.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Join me at 365EduCon in Chicago on Sept. 26-30 where I'll be presenting on the Power Platform!
v-xida-msft
Community Support
Community Support

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,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Mays
Helper I
Helper I

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

,Much appreciated 

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 (3,831)