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 / PATCH on multiple sel...
Power Apps
Suggested Answer

PATCH on multiple selected gallery items

(0) ShareShare
ReportReport
Posted on by 938
Trying to add a row in AP Ledgers Assignments table for each Line Item selected (by checkbox control) in gallery. The Gallery is he line items table.  The line item table is a lookup column in the AP Ledgers table - Getting 'The Specified column is not available in this context' error can't see what I'm doing wrong 
 
ForAll(
    Filter(gallineitems.AllItems, chkgalcode.Checked = true),
    Patch(
        'AP Ledger Assignments',
        Defaults('AP Ledger Assignments'),
           
        ThisRecord// The current record in the loop
        {
            Amount: 200.00, //DataCardValue9.Text // Replace with your column and value
            Invoice: galheader.Selected,
            InvoiceLineItem:ThisRecord.' AP Invoice Line Items',
            LedgerCode: DataCardValue10.Value
           
        }
    )
);
Categories:
I have the same question (0)
  • Suggested answer
    Kalathiya Profile Picture
    2,456 Super User 2026 Season 1 on at

    Your syntax is wrong in this part, and that’s what’s causing the error. 

    In Patch(), the third parameter must be a single record of field/value pairs. You can’t pass ThisRecord separately before the { } block. That’s why you’re getting the “The specified column is not available in this context” error.

    ForAll(
        Filter(gallineitems.AllItems, chkgalcode.Checked = true) As _obj,
        Patch(
            'AP Ledger Assignments',
            Defaults('AP Ledger Assignments'),
            {
                Amount: 200,
                Invoice: _obj.galheader.Selected,
                InvoiceLineItem: _obj.'AP Invoice Line Items', // Use column name here
                LedgerCode: _obj.DataCardValue10.Value
            }
        )
    )

    Note: _obj refers to the current row in the gallery, so whenever you want to access a column or control value from that row, use _obj.ColumnName or _obj.ControlName.

     

    If this response resolves your issue, please mark it as the Verified Answer so it can help other community members as well.
    ---------------------------------------------------------------------------------
     
    📩 Need more help? Mention @Kalathiya anytime!
    ✔️ Don’t forget to Accept as Solution if this guidance worked for you.
    💛 Your Like motivates me to keep helping!

     

  • Kalathiya Profile Picture
    2,456 Super User 2026 Season 1 on at
    Hello @ctedesco3307
     
    If this response resolves your issue, please mark it as the Verified Answer so it can help other community members as well.
  • Haque Profile Picture
    3,653 on at
    I assume @Kalathiya's code will work for sure.
     
    A bit better readability we can impose using With:
     
    With(
        {filteredItems: Filter(gallineitems.AllItems, chkgalcode.Checked)},
        ForAll(
            filteredItems,
            Patch(
                'AP Ledger Assignments',
                Defaults('AP Ledger Assignments'),
                {
                    Amount: 200,
                    Invoice: galheader.Selected,
                    InvoiceLineItem: 'AP Invoice Line Items',
                    LedgerCode: DataCardValue10.Value
                }
            )
        )
    )
     
  • Suggested answer
    Assisted by AI
    Bitcot Automations Profile Picture
    23 on at

    I believe @Kalathiya’s code should work correctly.

     

    For improved readability, we can structure it using the With function:

     

    If(
        !IsBlank(
            Trim(
                PlainText(
                    LookUp(
                        'DataSource',
                        Country.Value = varCountry && State.Value = varState,
                        Q14
                    )
                )
            )
        ),
        true,
        false
    )
     
    If this response resolves your issue, please mark it as the Verified Answer so it can help other community members as well.
     
     
  • WarrenBelz Profile Picture
    155,838 Most Valuable Professional on at
    Firstly @Kalathiya's code may be correct and I may be misreading the core of the issue here.
     
    You mentioned a Lookup column - I assume you are using SharePoint and the column is InvoiceLineItem. I am also assuming here that: -
    • The Invoice field is a Record (not Text or a number) as your reference galheader.Selected would return a Record.
    • DataCardValue10 is not in the gallery
     
    Firstly  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 (as in your case)
     
    Also Lookup columns require different treatment - in the below you need to refer to the field you are looking up in 'AP Ledgers' where I have YourLookedUpColumn
    Patch(
       'AP Ledger Assignments',
       ForAll(
          Filter(
             gallineitems.AllItems, 
             chkgalcode.Checked
          ) As _Data,
          {
             Amount: 200.00,
             Invoice: galheader.Selected,
             InvoiceLineItem: 
             {
                Value: _Data.' AP Invoice Line Items',
                Id:
                LookUp(
                   'AP Ledgers',
                   YourLookedUpColumn = _Data.' AP Invoice Line Items
                ).ID
             }
             LedgerCode: DataCardValue10.Value
          }
       )
    );
     
    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,838 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   

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