Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Unanswered

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

Like (0) ShareShare
ReportReport
Posted on 14 Dec 2022 15:58:35 by 72

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? 

  • AaronKnox Profile Picture
    510 Super User 2024 Season 1 on 19 Dec 2022 at 17:36:10
    Re: Incompatible type -- Global var for a RECORD is getting set to BOOLEAN?

    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!

  • cha_cha Profile Picture
    4,932 Super User 2025 Season 1 on 14 Dec 2022 at 16:07:46
    Re: Incompatible type -- Global var for a RECORD is getting set to BOOLEAN?

    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 

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Building Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 89 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 60

#3
stampcoin Profile Picture

stampcoin 48

Overall leaderboard