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 / How To Determine Model...
Power Apps
Unanswered

How To Determine Model vs Canvas in Code

(0) ShareShare
ReportReport
Posted on by 160

Is there a way to determine if you are in a Model vs a Canvas app in code?  I have looked through the component reference but don't see anything.

 

The only thing I have seen at all is looking at the mode.allowcatedHeight and if it's -1 it's Model.  The problem with that though is that Canvas also has -1 for the control during the init and it doesn't get updated to the real number until the updateView.

 

https://docs.microsoft.com/en-us/powerapps/developer/component-framework/reference/

 

Thanks,

 

Rick

I have the same question (0)
  • Ben Thompson Profile Picture
    1,400 on at

    You want something that is defined in a model driven app but is not valid in a canvas app.

     

    There are a few possibilities that match that requirement but the first one I found (others may be more accessible) would be:-

     

    context.client.isOffline() context.client.isOffline===undefined should be enough

     

    https://docs.microsoft.com/en-us/powerapps/developer/component-framework/reference/client/isoffline

  • DanielCox Profile Picture
    2 on at

    From what I'm seeing, context.client.isOffline is available in both model and canvas apps. 

     

    I don't see anything in the documentation that is a definitive indicator as to whether you're in a model or a canvas app, which is surprising. So you're probably better off choosing something that I wouldn't expect to show up in canvas apps, for example getGlobalContextObject. I'd recommend checking that like this:

     

    var inModelApp = window.hasOwnProperty('getGlobalContextObject');
    if (inModelApp){
     // do model app specific things
    }

     

     

    @ben-thompson:  If you can forgive me getting on my soapbox for a second, please don't ever check if an object is undefined in this way:

     

    if (x === undefined) { ... }

     

     

    The most correct version to test this would be something like this:

     

    if (typeof x === 'undefined') { ... }

     

     

    Why you may ask? Quite simply, undefined isn't a keyword in JavaScript, so you can set it to whatever you want. What can that lead to? Try it out for yourself:

     

    var undefined = 'x';
    var x = undefined;
    if (x === undefined) { alert('Surprise!'); }

     

     

    If anyone knows of a supported way to detect whether you're in a canvas app or a model app, please let us know. Otherwise, please cast your vote here.

     

    Hope this helps!

  • Diana Birkelbach Profile Picture
    3,072 Most Valuable Professional on at

    I have the same problem, because the components has to look different in model driven and canvas apps.

    In this blog (https://www.itaintboring.com/dynamics-crm/verifying-application-type-in-the-pcf-component/), Alex Shlega uses the "Xrm" object to decide if it's a model driven or canvas app. I don't know how safe it is to rely on that, but for now I don't have a better solution ether.

    As @DanielCox  said, please vote my idea (https://powerusers.microsoft.com/t5/Power-Apps-Ideas/Runtime-possibility-to-detect-if-the-PCF-is-running-in/idi-p/500232 ) to have a supported way to detect this.

    Best regards,

    Diana

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!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 551

#2
WarrenBelz Profile Picture

WarrenBelz 430 Most Valuable Professional

#3
Valantis Profile Picture

Valantis 298

Last 30 days Overall leaderboard