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 function with va...
Power Apps
Unanswered

Patch function with variable as the Datasource

(1) ShareShare
ReportReport
Posted on by 10

Hi. I am new to Powerapps

 

I have developed a small app which updates a sql table via an on premise gateway. Right now it is connected to a dummy table containing a small amount of data. 

 

I want to be able to declare the table/connection in a variable onStart so in future I would not have to go through each function to edit the DataSource. 

Original code:

 

If(
 CountRows(colTaskUpdates) > 0,
 Patch(DataTable,colTaskUpdates);

);
Clear(colTaskUpdates);
Refresh(DataTable)

 


I changed it to this thinking there would be no issues

 

Set(myConnection,DataTable);

If(
 CountRows(colTaskUpdates) > 0,
 Patch(myConnection,colTaskUpdates);
);
Clear(colTaskUpdates);
Refresh(myConnection)

 



In the Patch function with my code I get this message: "The first argument of 'Patch' should be a collection".
although the refresh function works with the variable.

Reading through the documentation I still could not find the answer to why the variable can not be passed. 

 

Thank you in advance

 

 

Categories:
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Khameda 

    First, there is no need to issue a Refresh on your datasource.  In PowerApps, your datasource will already reflect any changes you make.  Issuing a refresh will just kill your performance.

     

    Second, what you think is happening with the Refresh is not happening...it is not refreshing the datasource when in a variable.

     

    Finally, you cannot use a variable as you are.  You have to specifically define the datasource.  Using variables like that is very "programmatic"  - PowerApps is not a programming platform.  It is not "code", it is just formulas like you would have in Excel (as it was designed after that).

     

    I hope this is helpful for you.

  • Khameda Profile Picture
    10 on at

    @RandyHayes 

    Hi Randy. Thank you for your reply. 
    I understand your reply but it does not add up for me. 

     


    Finally, you cannot use a variable as you are.  

     



    I tried the variable in other functions as well. This one works. 

    Set(myConnection,DataTable);
    
    SortByColumns(Search(
     myConnection,
     search_input.Text,
     "Column1",
     "Column2",
     "Column3",
     "Column4"
    ),"Column1")

     Also this one

    CountRows(myConnection)

     

    So in the end for me it seems like it is only for the Patch function. And I still can not find an answer to why it is like this. 

  • olisa Profile Picture
    7 on at

    I have the same issue here. I tried the variable on filter function in PowerApps it worked but the patch function seems to behave differently. This simply means that if I have different data sources where each data source get its own records based on a given criteria I will have to duplicate the code into the total number of data source that I have just to explicitly define the data source in the patch function.  

  • Akser Profile Picture
    1,546 Moderator on at

    "I want to be able to declare the table/connection in a variable onStart so in future I would not have to go through each function to edit the DataSource."

     

    Why don't you use 'find and replace' when you want to change your connection? Shouldn't take you more then 1 minute. 

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 354 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 320

#3
Mohsin Ali Profile Picture

Mohsin Ali 246

Last 30 days Overall leaderboard