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 / Issue with Timesheet A...
Power Apps
Suggested Answer

Issue with Timesheet Approval – Data Not Updating Consistently in SharePoint Lists

(0) ShareShare
ReportReport
Posted on by

I am working on a Timesheet App in Power Apps integrated with SharePoint lists, and I am facing an intermittent issue during the approval process.

 

🔍 Scenario:

  • I have two SharePoint lists:

    1. Timesheet Summary (main list)

    2. Timesheet Details (child list)
  • When a user clicks on Approve, I am using two Patch/Update operations (fetch functions):

    • One to update the summary list
    • Another to update the details lis

⚠️ Issue:

  • Sometimes, both lists update correctly ✅
  • But sometimes:

    • Only one list (either summary or details) gets updated
    • The other list does not reflect the approval status   
  • There is no clear error shown in the app

    this is my code 
     
    If(
        CountRows(
            Filter(
                Gallery4_3.AllItems,
                !IsBlank(TextInput2_21.Text) || !IsBlank(ID)
            )
        ) > 0
        &&
        //(varTotalBillable + varTotalNonBillable) > 0,
        (
            // ✔ Paid Leave case
            Checkbox1_1.Value = true
           
            // ✔ Work case (hours required)
            ||
            (varTotalBillable + varTotalNonBillable) > 0
        ),
       
     
        // ✅ VALID → RUN APPROVAL
        If(
            !varProcessing,
     
            Set(varProcessing, true);
     
           /* If(
                IsBlank(varDraftGroupId),
                Set(varDraftGroupId,  User().Email & "-" & Text(DatePicker1.SelectedDate, "yyyymmdd")& "-" & Text(GUID()))
            );*/
     
            ClearCollect(
                colApprovedrows,
                Gallery4_3.AllItems
            );
     
            ForAll(
                colApprovedrows As g,
                If(
                    !IsBlank(g.TextInput2_21.Text) || !IsBlank(g.ID),
                    Patch(
                        TimeSheetworkdata,
                        If(
                           IsBlank(g.ID),
                           Defaults(TimeSheetworkdata),
                            LookUp(
                            TimeSheetworkdata,
                            ID = Value(g.ID)
                           
        )
    ),
                        {
                            DraftId: varDraftGroupId,
                            Status: {Value: "Approved"},
                            'Description of work': g.TextInput2_21.Text
                        }
                    )
                )
            );
     
            // Reload
            ClearCollect(
                colFormRows,
                Filter(
                    TimeSheetworkdata,
                    DraftId = Text(varDraftGroupId) &&
                    'Created By'.Email = User().Email
                )
            );
     
            // Approval table
            Patch(
                TimesheetApproval,
                Coalesce(
                    LookUp(TimesheetApproval, DraftId = varDraftGroupId),
                    Defaults(TimesheetApproval)
                ),
                {
                    DraftId: varDraftGroupId,
                    Status: {Value: "Approved"},
                    Totalhrs: varTotalBillable,
                    Totalnonbillhrs: varTotalNonBillable
                }
            );
    Clear(colFormRows);
            Notify("Timesheet approved successfully", NotificationType.Success);
     
            Set(varProcessing, false)
        ),
     
        // ❌ INVALID → BLOCK
        Notify(
            "Cannot approve. No valid records or hours found.",
            NotificationType.Error
        )
    )
Categories:
I have the same question (0)
  • Suggested answer
    WarrenBelz Profile Picture
    155,840 Most Valuable Professional on at
    I can see some bracketing logic issues there which I have suggested corrections below. I have also added a couple of other enhancements that may assist. Happy to go through them if you need to.
    If(
       CountRows(
          Filter(
             Gallery4_3.AllItems,
             !IsBlank(TextInput2_21.Text) || !IsBlank(ID)
          )
       ) > 0 &&
       Checkbox1_1.Value ||
       (varTotalBillable + varTotalNonBillable) > 0,
       Set(
          varProcessing, 
          true
       );
       Patch(
          TimeSheetworkdata,
          ForAll(
             Filter(
                Gallery4_3.AllItems, 
                !IsBlank(TextInput2_21.Text) || !IsBlank(ID)
             ) As g,
             {
                ID: g.ID,
                DraftId: varDraftGroupId,
                Status: {Value: "Approved"},
                'Description of work': g.TextInput2_21.Text
             }
          )
       );
       ClearCollect(
          colFormRows,
          Filter(
             TimeSheetworkdata,
             DraftId = Text(varDraftGroupId) &&
             'Created By'.Email = User().Email
          )
       );
       Patch(
          TimesheetApproval,
          Coalesce(
             LookUp(
                TimesheetApproval, 
                DraftId = varDraftGroupId
             ),
             Defaults(TimesheetApproval)
          ),
          {
             DraftId: varDraftGroupId,
             Status: {Value: "Approved"},
             Totalhrs: varTotalBillable,
             Totalnonbillhrs: varTotalNonBillable
          }
       );
       Clear(colFormRows);
       Notify(
          "Timesheet approved successfully", 
          NotificationType.Success
       );
       Set(
          varProcessing, 
          false
       ),
       Notify(
          "Cannot approve. No valid records or hours found.",
          NotificationType.Error
       )
    )
    The main one is the ForAll Patch. - ForAll is not designed to be a loop, although it can act that way if it contains an action inside it. ForAll creates a Table, which can be Patched in one action to the data source and will run much faster than individual Patches for each record. If it contains the ID of each record, it will update the specific records, if not it will create new records, so in your case, new or existing patches will be automatic.
     
    Also why bother with the first collection - just patch straight from the gallery (also to refer to the content of TextInput2_21, it needs to be from the gallery, otherwise you need to refer to the field in the colleciton with this data).
     
    Please Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider answering Yes to Was this reply helpful? or give it a Like
    Visit my blog
    Practical Power Apps    LinkedIn  
  • WarrenBelz Profile Picture
    155,840 Most Valuable Professional on at
    A quick follow-up to see if you received the answer you were looking for. Happy to assist further if not.
     
    Please Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider answering Yes to Was this reply helpful? or give it a Like ♥
    Visit my blog
    Practical Power Apps    LinkedIn   
  • Suggested answer
    11manish Profile Picture
    3,333 on at
    Patch operations are not transactional, so multiple updates or creates may not execute consistently. The best approach is to use Power Automate for reliable processing.
     
    Power Apps → triggers Flow → Flow updates both lists atomically
  • WarrenBelz Profile Picture
    155,840 Most Valuable Professional on at
    I need to respond to the reference to Power Automate as that is completely incorrect. I have used ForAll Patches for years on SharePoint lists sourced from both collections and galleries on high-usage production apps and found the process both completely reliable and very time/resource efficient.
     
    A flow would make it more complex - you would need to apply JSON to whatever table was being sent, then parse it all back in the Flow, write with Apply to each, send back a completed flag and refresh the data source.
  • 11manish Profile Picture
    3,333 on at
     
    In my experience, using ForAll + Patch for multiple record creation and updates can become inconsistent, especially as the volume or complexity increases.
     
    While it works well in many scenarios, there are known limitations:
    • No true transaction support (partial success can occur)
    • Potential inconsistency under load or parallel execution
    • Limited visibility into failures across multiple records
    Because of this, I’ve found that using Power Automate, although slightly more complex to implement, provides a more reliable and controlled approach for bulk operations.
  • WarrenBelz Profile Picture
    155,840 Most Valuable Professional on at
    I am always open to other options, even though they conflict with the 8 years I have been using this process quite extensively.
     
    If you are offering this as an alternative, it would be useful for you to set out the steps of the process you are proposing, so @AJ-22041117-0 has another option to progress with.
  • 11manish Profile Picture
    3,333 on at
     
    Of course, ForAll + Patch remains a valid and efficient approach for many scenarios, especially when performance and simplicity are priorities.
     
    This is just an alternative pattern that may help in cases where consistency and control become more critical.

    Happy to discuss further or refine this approach based on the specific use case

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 Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 424

#2
WarrenBelz Profile Picture

WarrenBelz 355 Most Valuable Professional

#3
11manish Profile Picture

11manish 290

Last 30 days Overall leaderboard