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 return ...
Power Apps
Answered

Patch function return value type is incompatible with the original record

(0) ShareShare
ReportReport
Posted on by 90

Hi, 

I am expereincing a datatype error: "incompatible type. we can't evaluate your formula because the context variable types are incompatible with the types of values in other places in your app". Seems like it is related to resetting the original variabe to the return value from the Patch function, but i am not sure. Please help me! 

 

I get a record from the datasource once the user login: 

 

Set(gblAppUserSettings, LookUp(UserSettings, User.UserId = gblAppUser.UserId));

 

I update a "Show Pinyin" user setting through a toggle. Within the onSelect action, I have the following code:

 

Set(gblAppUserSettings, Patch(
 UserSettings,
 gblAppUserSettings,
 {
 ShowPinyin: If(
 tglShowPinyin.Value = true,
 'ShowPinyin (UserSettings)'.Yes,
 'ShowPinyin (UserSettings)'.No
 )
 }
));

 

However, this is where i start getting all the errors related to the "gblAppUserSettings" type. 

chent7_1-1659446683786.png

chent7_0-1659446461262.png

 

What i have tried: 

1. I inspected the return value of the Patch function through the Variable view and both the old record and the new (updated) record have the same GUID id. Both these values are of type "record". 

2. I set a placeholder value "Set(gblAppUserSettings, Defaults(UserSettings))" at the very beginning, doesn't work. 

3. I rename "gblAppUserSettings" to "gblAppUserSettings1" in the onSelect function, and then change it back. The error goes away!! Everything works fine. I can update and run the app normally. But when i close the app and reopen it again, all the above errors come back : ( .... This is very weird...

 

Your help is much appreciated. 

 

 

Categories:
I have the same question (0)
  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @chent7 

    This is very common with the formula editor in PowerApps.

    PowerApps needs to infer the schema of all of the records you work with.  When you assign to a variable, it needs to infer from not only the provided schema, but also from any derived schemas (the lookup in this case as well as the patch).  Then, to add an if statement into the patch...well, the editor gets confused easily!!

    Once it gets confused, you have to jump through a lot of hoops to get it to not be confused.  Sometimes it is that you have to close and reopen, sometimes it is that you have to swap out the variable to something else.  It just depends on how it is inferring the schema.

     

    In your case, I would, instead of using the outcome record of Patch (which by all accounts should work) to assign to your variable, I would try to just do a lookup again directly after the Patch.

    i.e.

    Patch(......);

    Set(glkbAppUserSettings, LookUp(....))

     

    I hope this is helpful for you.

  • Scott_Parker Profile Picture
    1,090 on at

    Edit: The below incorrect and probably a bug with variables.

     

    I did some testing and apparently LookUp() actually sets a reference to a row in a collection. So, you don't even need to have the second Set() at all. You will see that the global variable will change on its own after the Patch(). Works the same for local variables made with UpdateContext(). The same doesn't occur if you use LookUp() on a data source, it's just for collections.

     

    If you want to break the reference made by LookUp() for some reason, you could wrap it in First(Table()):

     

     

    Set(gblAppUserSettings, First(Table(LookUp(UserSettings, User.UserId = gblAppUser.UserId))))

     

     

    But, as far as what causes PowerApps to get confused about what types are being stored for each value in a record, I'm not sure. I've had comparable issues with complex record patch and I've just had to reload the app or something. I can't remember off the top of my head.

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

    @Scott_Parker 

    You might want to recheck your thinking on that variable.  They are snapshots of values/records at a point in time.  They are not pointers to something that will update dynamically.  

    Where/how are you seeing what you are perceiving as a "pointer"?

  • Scott_Parker Profile Picture
    1,090 on at

    @RandyHayes 

    You're right, what I said isn't correct, but there is something weird going on. Adding this code to an Button OnSelect:

    Set(gblTest, LookUp(colExample, "value3" in Value));
    Patch(colExample, gblTest, {Value: "wut"});

    Then gblTest.displayName = "Value3". As expected.

     

    But, if I add a set around the patch:

    Set(gblTest, LookUp(colExample, "value3" in Value));
    Set(asdf, Patch(colExample, gblTest, {Value: "wut"}));

    Then gblTest.displayName = "wut". Not what I would have expected.

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

    @Scott_Parker 

    I'm not following you with the glbTest.displayName - you don't appear to be making any change to the displayName column in your formula.

     

    BUT...yes, there are always strange (from a development perspective) things that go on.

     

    Variables can have unusual results when compounded in a formula like that.  PowerApps is not a development platform, it is a formula based platform like Excel and thus, formulas are "evaluated", not compiled and run.  As such, you are completely at the mercy of how the PowerApps will evaluate the formula.  You will see strange things like that with variables and With scoped variables.  It is also not limited to collections.  You will see strange things happen with records when a datasource is in the mix.  Column names can become completely NOT what you wrote in your formula when evaluated.  This is more evident with DataVerse.  

     

    SO...general concept is to avoid variables any way.  Since data is evaluated in PowerApps, let it do so.  Unless you need some sort of "snapshot" of a value at some point in time, go with the underlying flow of how it all evaluates and it will give you what you expect.

     

    Now...all that said, I agree, there is, in general, some issue with what is going on.  A variable value should *never* change until the Set (or UpdateContext) statement is re-evaluated.  As it seems now, that is no longer the case - a variable is changing by itself.  

    This seems like a bug in the current version.  And yes, this seems to only happen with collections.  

     

    The unfortunate part of that is during this stage of the issue, people will start to think what you were - that it is some pointer.  PowerApps doesn't have any concept of a Pointer, so it is misleading.

     

    Thanks for pointing this out though.  It was interesting to see and it should definitely be reported as a potentially devastating bug! 

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!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 549 Most Valuable Professional

#2
Kalathiya Profile Picture

Kalathiya 225 Super User 2026 Season 1

#3
Haque Profile Picture

Haque 224

Last 30 days Overall leaderboard