web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

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:
I have the same question (0)
  • RandyHayes Profile Picture
    76,297 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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 711 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 319 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard