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 / Using ForAll and Patch...
Power Apps
Answered

Using ForAll and Patch ThisRecord

(0) ShareShare
ReportReport
Posted on by 32

I have two buttons on two different screens to patch to different SharePoint lists when a toggle has been set showing a record has changed. One works but the other one doesn't and I can't figure out why.

 

The one that works is OnSelect:

 

If(varM_DisplayMode="Edit",
ForAll(Filter(galM_Membership.AllItems, tgM_ChangeRecord.Value=true,Not(IsBlank(ddM_CommitteeCode))),
Patch(Membership, ThisRecord,
{M_CommitteeCode: Text(ddM_CommitteeCode.SelectedText.Value),M_CommitteeTitle: txtM_CommitteeTitle.Text})));

 

 

The one that doesn't, again under OnSelect, is:

 

If(varAP_DisplayMode="Edit",
ForAll(Filter(galAA_AgendaPlanner.AllItems, tgAA_ChangeRecord.Value=true,Not(IsBlank(ddAA_CommitteeCode))), 
Patch(AgendaPlanner, ThisRecord, {
AP_CommitteeCode: Text(ddAA_CommitteeCode.SelectedText.Value),AP_MeetingDate: DateValue(ddAA_MeetingDate.SelectedText.Value)})));

 

The error message isn't very helpful as all it says is 'The function 'Patch' has some invalid arguments'. Both codes look the same (apart from variable names) and it is driving me mad - I love PowerApps but why does it have to be so fickle?

 

Any help gratefully received.

Categories:
I have the same question (0)
  • DavidZoon Profile Picture
    738 Most Valuable Professional on at

    Hello,

    Try to add a format matching your combobox / dropdown 'DateValue(ddAA_MeetingDate.SelectedText.Value)'

     

    Or

     

    if ddAA_MeetingDate is a date picker, replace DateValue(ddAA_MeetingDate.SelectedText.Value) by

    ddAA_MeetingDate.SelectedDate

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily.

     

     

  • Geostation Profile Picture
    32 on at

    Thanks for the suggestion but it didn't work (assuming you meant replacing DateValue with Text(xxx, "d mmm yyy")). That control is a dropdown (of existing dates) and if I try and change it as suggested then thee is an error message as AP_MeetingDate is expecting a date. 

     

    I have tried commenting it out and that also doesn't work. 

  • WarrenBelz Profile Picture
    155,463 Most Valuable Professional on at

    Hi @Geostation ,

    Firstly, you have the ForAll backwards - you can use it as a loop but with significant performance penalty, but it creates a Table that can be applied in one Patch (not one per loop).

    I have to assume here that the value selected in ddAA_MeetingDate is a valid data format and that AP_MeetingDate is a Date/Time field. I also need to assume that you have the ID of the SharePoint item to be patched somewhere in the Gallery content.

    If(
     varAP_DisplayMode = "Edit",
     Patch(
     AgendaPlanner, 
     ForAll(
     Filter(
     galAA_AgendaPlanner.AllItems, 
     tgAA_ChangeRecord.Value && 
     !IsBlank(ddAA_CommitteeCode)
     ) As aPatch, 
     {
     ID: aPatch.ID,
     AP_CommitteeCode: aPatch.ddAA_CommitteeCode.Selected.Value,
     AP_MeetingDate: DateValue(aPatch.ddAA_MeetingDate.Selected.Value)
     }
     )
     )
    )

     

    Please click Accept as solution 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 giving it Thumbs Up.

    Visit my blog Practical Power Apps

  • Geostation Profile Picture
    32 on at

    Thanks for taking the time to respond, Warren, but unfortunately that hasn't worked. 

     

    I still have the "'Patch' has some invalid arguments" error message but now also have

    "'As' is not permitted in this context'' 

    "The type of this argument 'AP_CommitteeCode' does not match the expected 'Text'" "Invalid use of '.'" error associated with "aPatch.ddAA_CommitteeCode.Selected.Value" 

    "Name isn't valid. 'aPatch' isn't recognized" which I assume is due to the 'As' problem.

     

    For context, AP_CommitteeCode is a text field in SharePoint, ddAA_CommitteeCode is a dropdown box in the gallery . I have deleted the AP_MeetingDate line to simplify.

     

    I am not sure if the formula will pick up ID as I have been using ThisRecord and don't know how to identify the ID  - adding it as a suffix anywhere (even in a dummy field) doesn't seem to work.

     

    I appreciate the advice about changing the logic order to improve performance but (one of) my frustration(s) is that I have virtually the same configuration working on another screen so the logic must be sound (even if inefficient) and performance isn't my biggest problem at the moment (I am a hobbyist not a professional coder).

     

    I am sure that there must be something elsewhere in the code that makes this screen different than the one that is working but I have no idea what it might be,

     

    Again, really appreciate any help on offer. 

  • WarrenBelz Profile Picture
    155,463 Most Valuable Professional on at

    @Geostation ,

    Just a misplaced bracket - try now

  • Geostation Profile Picture
    32 on at

    Thanks again Warren, but there are now different errors - this time 'Unexpected characters: Characters are used in the formula in an unexpected way" against the 'As' statement and 'Expected operator: We expect an operator such as +,* or & at this point in the formula." 

     

  • WarrenBelz Profile Picture
    155,463 Most Valuable Professional on at

    @Geostation ,

    Can you please post the exact code you are using in Text - the structure I posted should be correct.

  • Geostation Profile Picture
    32 on at

    Thanks Warren, see below. I am working on  copy of the screen so the dropdown name has changed. I think there should be a comma before As aPatch as the below version shows an 'if' error.

     

    If(
    varAP_DisplayMode = "Edit",
    Patch(
    AgendaPlanner,
    ForAll(
    Filter(
    galAA_AgendaPlanner.AllItems,
    tgAA_ChangeRecord.Value &&
    !IsBlank(ddAA_CommitteeCode)
    ) As aPatch,
    {
    ID: aPatch.ID,
    AP_CommitteeCode: aPatch.ddAA_CommitteeCode1.SelectedText.Value,
    AP_MeetingDate: DateValue(aPatch.ddAA_MeetingDate1.SelectedText.Value)
    }
    )
    )
    );
    If(varAP_DisplayMode="View",
    Set(varAP_DisplayMode, "Edit"),
    Refresh(AgendaPlanner),
    Set(varAP_DisplayMode, "Edit"));
    ClearCollect(colAgendaPlanner,AgendaPlanner)

  • Verified answer
    WarrenBelz Profile Picture
    155,463 Most Valuable Professional on at

    Hi @Geostation ,

    The structure of this is correct

    If(
     varAP_DisplayMode = "Edit",
     Patch(
     AgendaPlanner,
     ForAll(
     Filter(
     galAA_AgendaPlanner.AllItems,
     tgAA_ChangeRecord.Value &&
     !IsBlank(ddAA_CommitteeCode)
     ) As aPatch,
     {
     ID: aPatch.ID,
     AP_CommitteeCode: aPatch.ddAA_CommitteeCode1.Selected.Value,
     AP_MeetingDate: DateValue(aPatch.ddAA_MeetingDate1.Selected.Value)
     }
     )
     )
    );

    assuming varAP_DisplayMode is a Text Variable, tgAA_ChangeRecord is a Toggle control in the gallery and ddAA_MeetingDate1 outputs a text value with a valid date structure, however what is ddAA_CommitteeCode (is it a drop-down in the gallery - in which case you need ddAA_CommitteeCode.Selected.xxxx where xxxx is the valid output.

    Also note SelectedText is deprecated - you need Selected.

     

    Please click Accept as solution 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 giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

     

     

  • Geostation Profile Picture
    32 on at

    So, its now working but the solution is a combination of your advice, Warren, correcting an error I had missed (I was using a copy of the original screen so ddAA_CommitteeCode should have been ddAA_CommitteeCode1, and trial and error. If I use Selected instead of Selected.Text then it doesn't work so not sure what the issue is there,

    I'm grateful for you taking the time to review and your patience with my inexperience, and have posted the corrected code below.

     

    If(
    varAP_DisplayMode = "Edit",
    Patch(
    AgendaPlanner,
    ForAll(
    Filter(
    galAA_AgendaPlanner.AllItems,
    tgAA_ChangeRecord.Value = true,
    !IsBlank(ddAA_CommitteeCode)
    ) As aPatch,
    {
    ID: aPatch.ID,
    AP_CommitteeCode: aPatch.ddAA_CommitteeCode.SelectedText.Value,
    AP_MeetingDate: DateValue(aPatch.ddAA_MeetingDate.SelectedText.Value)
    }
    )
    )
    )

     

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 742

#2
Valantis Profile Picture

Valantis 474

#3
Haque Profile Picture

Haque 358

Last 30 days Overall leaderboard