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 / Conflict using Set and...
Power Apps
Suggested Answer

Conflict using Set and Patch

(1) ShareShare
ReportReport
Posted on by 10
I've been writing an app for work.  In App.OnStart I initialize a global variable called varUser and populate it is a record with multiple fields such as name, email, orgSymbol, role, etc.
Set(varUser, {
     name:Office365Users.MyProfileV2().displayName,
     email:Office365Users.MyProfileV2().userPrincipalName,
     role:First(Filter('Personnel DB',email = Office365Users.MyProfile().UserPrincipalName)).role,
     org:First(Filter('Personnel DB',email = Office365Users.MyProfile().UserPrincipalName)).org
     }
);
That seems to work fine.  I'm able to use varUser.org and varUser.role throughout my app. But then I need to change one of them based upon a dropdown list.
 
Set(varUser, Patch(varUser, {
     role:dropDownRole.Selected.Value,
     org:dropDownOrg.Selected.Value
    }
));
And that fails.
 
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.
 
What gives?  role and org are both text values in the Personnel DB.  The drop down items are all text.  What am I doing wrong?
Categories:
I have the same question (0)
  • Suggested answer
    WarrenBelz Profile Picture
    155,838 Most Valuable Professional on at
    I am not sure if you have some mis-types in the second code, but I tested this here and it worked fine. 
     
    I used your code (small suggestion below) for setting the Variable using a similar list I have here (both role and org are Single Lines of Text
    With(
       {
          _User: LookUp(
             'Personnel DB',
             email = Office365Users.MyProfile().UserPrincipalName
          )
       },
       Set(
          varUser,
          {
             name: Office365Users.MyProfileV2().displayName,
             email: Office365Users.MyProfileV2().userPrincipalName,
             role: _User.role,
             org: _User.org
          }
       )
    );
    then this patched the new text values I had from two single selection drop-downs - I assume Value is the correct output for yours.
    Set(
       varUser, 
       Patch(
          varUser, 
          {
             role: dropDownRole.Selected.Value,
             org: dropDownOrg.Selected.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  
  • LampreyGuy Profile Picture
    10 on at
    Thanks for the suggestion, but still not there.  I realized there is another piece of the puzzle, components.  In App.OnStart I'm creating the varUser global variable.  I have a component with a menu bar, and on that menu bar I have my drop down of other org names and a button to change the varUser.orgSymbol.  I created a new app with only three controls: a component with the dropdown and a button, and a text label on a screen.
     
     
    App.OnStart includes the following...
     
    Set(
        varUser,
        {
            email: Office365Users.MyProfileV2().userPrincipalName,
            orgSymbol: Text(First(Filter('Personnel',email = Office365Users.MyProfile().UserPrincipalName)).orgSymbol),
            role: Text(First(Filter('Personnel',email = Office365Users.MyProfile().UserPrincipalName)).role),
            name: Office365Users.MyProfileV2().displayName
        }
    );
     
    The OnSelect of my button is...
    Set(varUser, Patch(varUser, {orgSymbol:Dropdown1.Selected.Value}));
    Access App Scope is enabled on my component. And this happens...
     
     
    If the dropdown and button were on the screen, it works fine.  But introducing it in a component, and it fails.
     
  • Suggested answer
    11manish Profile Picture
    3,333 on at
    The error occurs because Power Apps inferred a different data type (likely a record such as a Choice or Lookup) for role and org when the variable was first initialized, but you are later trying to assign plain text values.
     
    To fix this, either normalize the fields to text from the beginning or maintain the same record structure when updating.
     
    Also, avoid using Patch on variables—use Set with a full record update instead.
  • LampreyGuy Profile Picture
    10 on at
    Role and org were initialized as text values. The syntax pulled the first record from a filter operation and then picked the appropriate element out of that record. 
     
    Right now it seems the most likely culprit is the fact that the component is trying to modify a global variable, which apparently is not a good programming practice.
  • Suggested answer
    TechFreak Profile Picture
    149 on at

    Hi,

    The issue you’re facing is due to how Power Apps handles record typing for variables.

    What’s happening

    When you initialize varUser in App.OnStart, Power Apps infers a fixed schema (structure + data types) for that record based on the initial values:

     
    Set(varUser, {
    name: Office365Users.MyProfileV2().displayName,
    email: Office365Users.MyProfileV2().userPrincipalName,
    role: First(Filter('Personnel DB', email = Office365Users.MyProfile().UserPrincipalName)).role,
    org: First(Filter('Personnel DB', email = Office365Users.MyProfile().UserPrincipalName)).org
    })
     

    Now varUser.role and varUser.org are typed based on what comes from 'Personnel DB'.

     

    Why your Patch fails

    This line:

     
    Set(varUser, Patch(varUser, {
    role: dropDownRole.Selected.Value,
    org: dropDownOrg.Selected.Value
    }))
     
     

    fails because:


    • Patch() is meant for data sources, not for updating local records

    • It tries to merge records with potentially different inferred types

    • Even if both look like text, Power Apps may treat them differently internally (e.g., Choice vs Text)
       

    Correct approach (Update record directly)

    Use record update syntax instead of Patch:

     
    Set(
    varUser,
    {
    name: varUser.name,
    email: varUser.email,
    role: dropDownRole.Selected.Value,
    org: dropDownOrg.Selected.Value
    }
    )

    Cleaner approach using With() or record merge

    If you want a more maintainable way:

     
    Set(
    varUser,
    varUser & {
    role: dropDownRole.Selected.Value,
    org: dropDownOrg.Selected.Value
    }
    )
     
     

    Pro Tip

    If your dropdown is bound to Choices(...), sometimes .Value vs .Result matters. If you still see issues, verify using:
     

    ​​​​​​​JSON(dropDownRole.Selected)
     
     

    Summary


    • Patch() is not suitable for updating local variables

    • Power Apps enforces strict record typing once a variable is initialized

    • Use record reassignment or merge (&) to update fields

    •  

     

    If this resolves your issue, please mark the answer as accepted and give it a like. It helps others in the community and supports knowledge sharing. Thanks!

  • WarrenBelz Profile Picture
    155,838 Most Valuable Professional on at
    Please note that the long ChatGPT copy/paste response is completely incorrect (in may ways) - you certainly can update a Table Variable. 
     
    I probably need to remind responders that it is important to follow The Responsible AI policies for the Community so the content can be considered in the proper context.
  • 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