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 / Updating Context Varia...
Power Apps
Suggested Answer

Updating Context Variables with Tables

(0) ShareShare
ReportReport
Posted on by 765 Super User 2024 Season 1

I have a context variable that contains a table. I want to update a record in that table with either Patch() or UpdateIf(). I keep getting an error that the first parameter to Patch() or UpdateIf() needs to be a collection. It is a collection. Do these functions have issues with Tables that are in a Context Variable? Does the variable need to be actual collection? Why can't it be a Table, I should be able to update a table!

 

This is frustrating, I HATE using variables with Global context when they are not needed. Is there a way to do this?

 

Thank you.

Categories:
I have the same question (0)
  • AhmedSalih Profile Picture
    6,680 Moderator on at

    Hello, @sperry1625, are you using the Table() function? If so, I would suggest that you load your table into a collection.

  • sperry1625 Profile Picture
    765 Super User 2024 Season 1 on at

    Why? Collections are global, I really do not want to use a Global variable. Is there really no way to update a Table that is in a Context Variable or created using Set()?

     

    Thank you.

  • AhmedSalih Profile Picture
    6,680 Moderator on at

    @sperry1625, As the error mentioned, UpdateIF and patch won't work with data table created with the Table() function. If the issue of creating collection is because of the performance, you can utilize the clear function always to clear up the data in the collection. 

  • Pstork1 Profile Picture
    69,653 Most Valuable Professional on at

    Context variables are objects, not collections.  You may have an array (Table) embedded in the context variable, but the variable itself isn't a collection.  Try embedding the table as a property and then doing an update if on that property.

  • francoisb1 Profile Picture
    21 on at

    Hi @sperry1625 

    I have the same questions. 

    I need a table but want to avoid using global scope and so I don't use Collection.

    Same idea is to store the table in a context variable.

    But did you manager to update / add item to the table ?

  • Pstork1 Profile Picture
    69,653 Most Valuable Professional on at

    Please post this as a new question.  You'll get more responses and others will be able to find the answer more easily later.

  • Suggested answer
    james_hathaway Profile Picture
    427 on at
    I figured this one out...
     
    I have a Table inside my Context called "_recordTable" defined as below.
     
    UpdateContext({
        _recordTable:Filter(Customers,Active)
    })
    (Where "Customers" is a legitimate Datasource)
     
    If I wanted to Patch or update that table, I ran into the same issue as the OP.
     
    SOLUTION:
     
    After a bit of digging and experimentation, I found the following works:
     
    As Pstork1 suggested - The trick is to put the table inside another property in the Context record...
    UpdateContext({
        _recordTable: {
            _table:Filter(Customers,Active)
        }
    });
    
    Patch(_recordTable._table, {ID:recordToUpdate.ID}, {Active:false});
     
    J.

    EDIT - After more experimentation, this solution does NOT actually work.
    Although there is no error in the Studio, and No Runtime error displayed at all, the table is simply NOT updated at all.
    This is misleading enough, because it acts as though the code runs perfectly, but it clearly produces an error.

    If you set a variable to the result of the Patch with:
    Set(_response,Patch(_recordTable._table, {ID:recordToUpdate.ID}, {Active:false}));

    The variable "_response" shows the value:
    Error - (The Data source supplied to the function is invalid)

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

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 379 Most Valuable Professional

#2
11manish Profile Picture

11manish 203 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 128 Super User 2026 Season 2

Last 30 days Overall leaderboard