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 / Incompatible type -- G...
Power Apps
Unanswered

Incompatible type -- Global var for a RECORD is getting set to BOOLEAN?

(0) ShareShare
ReportReport
Posted on by 74

Canvas app with SharePoint data source. I'm on GCC High. 

 

I keep running into this issue where my global variable gets broken. I'm setting it when the user selects a gallery item: Set(varMyRecord, ThisItem), then I navigate to another screen where a form is set to Item: varMyRecord. It works fine for a day or so, then breaks and I have to change the var name to correct it. I understand that I can't go around setting the same variable to a string in one spot and a record in another -- but I'm not. 

 

I do have some trickiness going on b/c I'm using the variable to create an appended text gallery (using Shane Young's method), but at no time am I consciously setting the variable to be something other than a RECORD. Hovering over one function, the powerapps told me the variable was a boolean. How on earth did that happen? How can I get around this? 

Categories:
I have the same question (0)
  • cha_cha Profile Picture
    4,932 Moderator on at

    Hello @RacRig5407 

     

    To trace the variable assigning of value, go here:

    cha_cha_0-1671033905288.png

    Then 

    cha_cha_1-1671033996738.png

    Then look at the definition tab. there you will see which part of your app is your variable getting assigned with a boolean.

    cha_cha_2-1671034034783.png

     

     

     

     

     

    Also, clear the cache and maybe close/open your browser as it may be just a usual power app cache issue

     


      ✔️
    Just in case my response helped you solve your problem, please mark/accept this as a SOLUTION This helps community members if they experience a similar issue in the future.

     

      🔗
    🕸bistek.space  🐦 @cha_bistek  📺 @BisTekSpace 
  • AaronKnox Profile Picture
    514 Super User 2024 Season 1 on at

    Hi @RacRig5407 ,

    The exception to the official Microsoft documentation 'Performance tips and best practices'  is actually a best practice for many scenarios:

    There's an exception: In the previous example, imagine that the only way to display screen 1 is by navigating from screen 2. Then screen 2 will have already been loaded in memory when screen 1 is to be loaded. No extra work is needed to fulfill the dependency for screen 2, and therefore there's no performance impact.

     

    Best practice:  If the user must first select something from a gallery, dropdown, or combo, you can simply reference gallery.Selected, dropDown.Selected, or comboBox.SelectedItems for the entire app!  No need for a global variable! Unless you are doing some serious data manipulation from when the user selects an item to when you write back to the data source, try to avoid global variables as they can lead to mutable problems you seem to be experiencing.  Even then I'd say you can get away with most of that data manipulation at the time of update, for instance in a datacard's update property (datacard1.Update), or added logic to a patch statement.

     

    Further, if you think 'Well, I have a deep-link, so this pattern will not work for that', think again!  The gallery.Default property is the way to maintain this pattern with deeplinks as well:

    gallery.Default:  

     

    If( !IsBlank(Param("recordGUID")),LookUp(galleryDataSource,recordGUIDSLT=Param("recordGUID")) )

     

     

    It might not be as clear with dropdowns as it is with galleries and combos, but you can load an entire record into a dropdown control to maintain this pattern.  Even though the dropdown can only show one of those values from the record, the entire record gets selected.

    For example, if you have a dropdown with:

    Dropdown1:Items mySharePointListName

    Then make sure Title (or other text field) is in the Value property on the right hand pane:

    CaptureW1.JPG

    Once the user makes a selection, you have access to that entire SharePoint record for the entire app.  So as an example, to show the user that created the selected SharePoint record, you could provide this code later in the app:

     

    Dropdown1.Selected.'Created By'.DisplayName

     

     

    Avoiding global variables is considered a programming best practice, even for PowerApps.  Avoiding global variables has been a tenant of JavaScript programming from the very beginning which has led to many different methods of dealing with this problem over the years.  Though it is a bit outdated, this excellent JavaScript video series goes over why you want to avoid global variables, and how you can add a little extra code to create a 'module' using the object literal/anonymous self executing function pattern. 

     

    Luckily for us, just about everything in PowerApps is a kind of module and has it's own API with properties you can reference nearly anywhere in the app!

     

    Cheers!

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…

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
Kalathiya Profile Picture

Kalathiya 445

#2
WarrenBelz Profile Picture

WarrenBelz 386 Most Valuable Professional

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 321 Super User 2025 Season 2

Last 30 days Overall leaderboard