Skip to main content
Community site session details

Community site session details

Session Id : g8Png7u4ByDelDf7QpxS/R
Power Apps - Building Power Apps
Answered

Updating leave balance on sharepoint not being updated when request is approved

Like (0) ShareShare
ReportReport
Posted on 19 Jan 2024 20:44:54 by 67

I'm working on the leave balance template and I have changed the data source to sharepoint. Everything works as expected except when a leave request is approved, the balance does not update to reflect the change, for example I made a request for vacation and had it approved. It is supposed to update the "vacation used" portion when the request is approved.If i enter it manually from the list the change is reflected on the app.

vacation example.png

Vacation Used.png

This is the code used on the approver button 

 

 

Concurrent(
 Set(_submittingRequest, true),
 //when approving leave, add the respective days used to the respective used days field
 Patch(Balance, LookUp(Balance, BalanceID = _requesterBalanceRecord.BalanceID),
 If(Upper(GalleryRequests.Selected.LeaveType) = Upper("Vacation"), {VacationUsed: _requesterBalanceRecord.VacationUsed + _requestedDays},
 Upper(GalleryRequests.Selected.LeaveType) = Upper("Sick leave"), {SickUsed: _requesterBalanceRecord.SickUsed + _requestedDays},
 Upper(GalleryRequests.Selected.LeaveType) = Upper("Floating holiday"), {PersonalUsed: _requesterBalanceRecord.PersonalUsed + _requestedDays},
 Upper(GalleryRequests.Selected.LeaveType) = Upper("Jury duty"), {JuryDutyUsed: _requesterBalanceRecord.JuryDutyUsed + _requestedDays},
 Upper(GalleryRequests.Selected.LeaveType) = Upper("Bereavement"), {BereavementUsed: _requesterBalanceRecord.BereavementUsed + _requestedDays}
 )
 ),
 Set(_managerApprove, true));
Patch(Leave, LookUp(Leave, LeaveID = GalleryRequests.Selected.LeaveID), {Status: "Approved"});
Set(_submittingRequest, false);
Navigate(ManagerChangeRequestScreen, BorderStyle.None);
 

 

 

I made a previous topic on this but I'm not sure I was very clear about the issue I'm having. Previous topic  
I'm new here to the forum so I'm not certain how I would go about deleting my old post or updating it, just wanted to clarify the issue.

I attempted adding an altered version of the code: But it did not change. All permissions on sharepoint are set so that a user can edit the form when created by another user so it should be updated. Is there something I'm missing ?

 

 

Concurrent(
 Set(_submittingRequest, true),
 // when approving leave, add the respective days used to the respective used days field
 Patch(
 Balance,
 LookUp(Balance, BalanceID = _requesterBalanceRecord.BalanceID),
 {
 VacationUsed: If(
 Upper(GalleryRequests.Selected.LeaveType) = Upper("Vacation"),
 _requesterBalanceRecord.VacationUsed + _requestedDays,
 _requesterBalanceRecord.VacationUsed
 ),
 SickUsed: If(
 Upper(GalleryRequests.Selected.LeaveType) = Upper("Sick leave"),
 _requesterBalanceRecord.SickUsed + _requestedDays,
 _requesterBalanceRecord.SickUsed
 ),
 PersonalUsed: If(
 Upper(GalleryRequests.Selected.LeaveType) = Upper("Floating holiday"),
 _requesterBalanceRecord.PersonalUsed + _requestedDays,
 _requesterBalanceRecord.PersonalUsed
 ),
 JuryDutyUsed: If(
 Upper(GalleryRequests.Selected.LeaveType) = Upper("Jury duty"),
 _requesterBalanceRecord.JuryDutyUsed + _requestedDays,
 _requesterBalanceRecord.JuryDutyUsed
 ),
 BereavementUsed: If(
 Upper(GalleryRequests.Selected.LeaveType) = Upper("Bereavement"),
 _requesterBalanceRecord.BereavementUsed + _requestedDays,
 _requesterBalanceRecord.BereavementUsed
 )
 }
 ),
 Set(_managerApprove, true)
);

Patch(Leave, LookUp(Leave, LeaveID = GalleryRequests.Selected.LeaveID), {Status: "Approved"})
Set(_submittingRequest, false);
Navigate(ManagerChangeRequestScreen, BorderStyle.None);

 

 




Categories:
  • Universal_Power Profile Picture
    67 on 22 Feb 2024 at 14:21:30
    Re: Updating leave balance on sharepoint not being updated when request is approved

    Hi @MoZiZo this looks like something a bit different form what I was going through but it looks like you have a problem with your connection, you used sharepoint but did you link it back in the app itself? did you add those "sick used" and "vacation used" days yourself? Or was it done from the app.

  • MoZiZo Profile Picture
    5 on 21 Feb 2024 at 15:17:40
    Re: Updating leave balance on sharepoint not being updated when request is approved

    Hi @Universal_Power
    I am using the same app you are using and i have similar issue you mentioned here, can you please explain more how you fixed this issue. 

    My issue is :

    the column called "Vacation" or "Sick" is not updated with the new value as per the below screen 

    MoZiZo_0-1708528504626.png

    however, on the app everything is working fine and i can see the new value.

    MoZiZo_1-1708528598969.png

     

    Do you have any idea how i can fix this issue? 

  • Universal_Power Profile Picture
    67 on 26 Jan 2024 at 00:58:50
    Re: Updating leave balance on sharepoint not being updated when request is approved

    Update: @WarrenBelz  Solution worked, there was an issue with my variables, _requesterBalanceRecord was not being called. Thanks really appreciated

  • Universal_Power Profile Picture
    67 on 24 Jan 2024 at 12:37:30
    Re: Updating leave balance on sharepoint not being updated when request is approved

    @WarrenBelz Yes there are other fields in the list, balanceID is there however I also attempted to use the employeeEmail to patch it and it still was not inputting the data into the correct record. Is there something missing that I'm not inputting for it to patch correctly? 

    Universal_Power_0-1706099618762.png

     

  • WarrenBelz Profile Picture
    148,811 Most Valuable Professional on 23 Jan 2024 at 20:57:46
    Re: Updating leave balance on sharepoint not being updated when request is approved

    @Universal_Power ,

    That is the first thing that was posted and you said it was not correct. I also cannot see BalanceID in the screenshot of your list below

    WarrenBelz_0-1706043300249.png

    One of these fields (I suspect EmployeeEmail or EmployeeName ) needs to be used to identify the correct record to Patch (unless there are other fields in the list you have not included above), so you simply need to retrieve that somewhere from the data you are using.

     

  • Universal_Power Profile Picture
    67 on 23 Jan 2024 at 20:07:14
    Re: Updating leave balance on sharepoint not being updated when request is approved

    @WarrenBelz  Sorry for the delayed response, I've been off for a little. I took the time today to try to understand what's going on. I know now that the patch function is updating the balance data source based on the identifier _Data which is the variable that was set using balanceID=_requesterBalanceRecord.BalanceID. 

    With that being said, to answer your question, the employee email is not the relevant field, there is infact a unique BalanceID field within the data source. I believe that the requesterBalanceRecord is where the issue lies. Is it that this variable was not correctly defined ? 

    For reference to all of this, I am using this from github where this person created the sharepoint connection to the leave app. https://github.com/powerappstim/leaverequest 

  • WarrenBelz Profile Picture
    148,811 Most Valuable Professional on 20 Jan 2024 at 04:53:53
    Re: Updating leave balance on sharepoint not being updated when request is approved

    @Universal_Power ,

    The underlying issue is that you cannot update a record in a data source without referring to a field it it to identify which record to update. If it is not a unique identifier (there are other records with the same value in the field), you may update the wrong record, but you can update them all if you want to.

    So in short, is the employee email this relevant field and if so, is this value contained in varRequestorRecord or alternatively is there a list somewhere that contains both the email address and also the corresponding BalanceID for that employee ?

    If there is no field (as you noted) that correlates, then there is no way to identify which record to update and you need to revise your data structure so that this exists.

  • Universal_Power Profile Picture
    67 on 20 Jan 2024 at 01:10:56
    Re: Updating leave balance on sharepoint not being updated when request is approved

    @WarrenBelz Okay I checked the global variables for RequesterBalanceRecord and In home screen on visible there's a lookup function similar to the one you wrote out where it pulls the record from the o365 profile, to me it looks like it's setting the Requesterbalancerecord variable using the _myprofile information ? Or could the unique identifier be employeeEmail?  Below is a snippet of it;

    Concurrent(
     Set(_navMenuSelect, "My Leave Requests"),
     //if not manager view, refresh my balance collection when on this screen
     If(!_managerView, Set(_requesterBalanceRecord, LookUp(Balance, Year = Text(Year(Now())) && EmployeeEmail = _myProfile.UserPrincipalName));
     ClearCollect(RequesterBalanceCollection, 
     { type: "Vacation", balance: Value(_requesterBalanceRecord.Vacation) - Value(_requesterBalanceRecord.VacationUsed)},
     {type:"Sick Leave", balance:Value(_requesterBalanceRecord.Sick)-Value(_requesterBalanceRecord.SickUsed)},
     {type:"Personal", balance:Value(_requesterBalanceRecord.Personal)-Value(_requesterBalanceRecord.PersonalUsed)},
     {type:"Jury Duty", balance:Value(_requesterBalanceRecord.JuryDuty)-Value(_requesterBalanceRecord.JuryDutyUsed)},
     {type:"Bereavement", balance:Value(_requesterBalanceRecord.Bereavement)-Value(_requesterBalanceRecord.BereavementUsed)},
     {type:"Paternity", balance:Value(_requesterBalanceRecord.Paternity)-Value(_requesterBalanceRecord.PaternityUsed)},
     {type:"Bereavement", balance:Value(_requesterBalanceRecord.Study)-Value(_requesterBalanceRecord.StudyUsed)}
     ,
     Set(_showDetails, false)
     )));

    To answer your question directly there is no field on the sharepoint list that directly correlates to requesterbalancerecord. Also all other uses of the global variable requesterbalancerecord only displays there is no "set" function.

  • WarrenBelz Profile Picture
    148,811 Most Valuable Professional on 20 Jan 2024 at 00:25:10
    Re: Updating leave balance on sharepoint not being updated when request is approved

    @Universal_Power

    OK - I will ask the question another way - which field here is a unique record identifier and is present in (I assume a Record Variable) RequestorBalanceRecord

    LeaveBalances.png

     

  • Universal_Power Profile Picture
    67 on 19 Jan 2024 at 22:57:46
    Re: Updating leave balance on sharepoint not being updated when request is approved

    @WarrenBelz  So I'm fairly new to power apps so bare with me a bit, The BalanceID field in my Balance sheet is automatically pulled from office365 users(which is matched in the gallery), so my BalanceID is my email and the date it was created which was auto generated upon logging into the leave app. What I'm seeing is that it's not pulling my specific balanceID but rather creating a blank balance ID and it's creating a "new" instance of it without the o365 data in the balance sheet.

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

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 791 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 410

#3
mmbr1606 Profile Picture

mmbr1606 275 Super User 2025 Season 1