cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
PedroFernandes
Helper II
Helper II

Update balance leave request

Hi

I'm building a leave request application using PowerApps for Teams. Here, the users from a Office365Users work group can make their requests and a manager can review and approve or reject them.

 

The app is almost complete, I have a table that records all the requests, and each request has a field "TimeRequested" that records how much time is being requested (using hours in this example).

 

The last thing I need to do (I'm struggling with that) is to record how many hours each user has remaining: I think I would need a new table for that ("LeaveBalance"), with at least a field for the user name or email, and a "TimeRemaining" field.

 

The image below shows the manager page with all the pending requests: when the manager clicks on the green button, that request status is updated to "Approved", and to "Rejected" by clicking the red button (those are choice values on the request table). That change occurs only on the selected request (that's why all pending requests have those buttons).

 

What I would like to do is, when pressing the "Approved" button, the "TimeRequested" value of that request would subtract to the "TimeRemaining" of the "LeaveBalance" table. Also, the formula should also speficy which user is making the request so it can subtract to the correct user on "LeaveBalance".

 

Any idea how can I achieve this? Please tell me if I need to clarify something.

Thank you

Pedro Fernandes
64564536456456.png

5 REPLIES 5
JR-BejeweledOne
Super User
Super User

Where does your app get the initial leave balance for your employees?



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.

That's something I still need to implement: I could add a field like "InicialLeaveTime" on the "LeaveBalance" table.

But since that inicial value would change from the moment the first request is approved, wouldn't be simpler to manually add that value to the "TimeRemaining" field when the entry for an user is created?

JR-BejeweledOne
Super User
Super User

The way I read your post, you don't currently have a Time Remaining field?

 

If you have not already calculated the number of days, you will need to do that.   Then on approve you would patch your inicial value or time remaining, whichever you are going to use:

 

Patch(datasource, {incialvalue: incialvalue - number of days}

 

 



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.
PedroFernandes
Helper II
Helper II

Meanwhile I created that field and gave it a number value (176, in this case),

My formula is something like this (some names are translated to english):

Patch(LeaveBalance, 
    
   {
      User: ThisItem.'Created By',
      TimeRemaining: TimeRemaining - tempVar2
   }
)

 

Note: tempVer2 is a local variable that stores the "TimeRequested" of that specific request.

I get an error on that last line of code, saying the name isn't valid, the identifier isn't recognized (error points to the second time "TimeRemaining" is written on that line)

JR-BejeweledOne
Super User
Super User

Since it appears that this is a newly created record that won't have any data in the record, you will need to capture the beginning balance and subtract the tempVar2 from that the first time you create this record.   After that you can update the record. 

 

Try this: Replace beginning balance with the information you captured.

Patch(LeaveBalance, 
    
   {
      User: ThisItem.'Created By',
      TimeRemaining: BeginningBalance - tempVar2
   }
)

 

 



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (1,226)