Embedding Canvas Apps in Forms
Complete the full lesson to earn 25 points
Work through each section, then tap “Mark as Complete” on the last one.
✦ Skip the page breaks and see fewer ads — read each lesson on a single page with Pro
Lesson: Embedding Canvas Apps in Model-Driven Apps
Introduction: Bridging the Gap Between Structure and Flexibility
In the world of Microsoft Power Platform, we often deal with two distinct paradigms: Model-Driven Apps and Canvas Apps. Model-Driven Apps are the backbone of enterprise data management. They are built on top of the Microsoft Dataverse, providing a structured, form-based interface that is excellent for managing relational data, complex business processes, and standardized workflows. However, they can sometimes feel rigid when you need a highly specialized, pixel-perfect user interface or a unique visual experience that doesn't fit the standard form layout.
On the other hand, Canvas Apps offer complete creative control. You can drag and drop components anywhere on the screen, use custom shapes, and build interfaces that function more like traditional web applications. The challenge has always been that Canvas Apps exist in their own silo, disconnected from the structured, data-centric environment of Model-Driven Apps.
Embedding a Canvas App into a Model-Driven form is the bridge between these two worlds. It allows you to maintain the robust data integrity and administrative features of a Model-Driven App while injecting the custom, user-friendly, and highly interactive interface of a Canvas App exactly where you need it. This combination is essential for scenarios where users need to interact with related records in a non-standard way, visualize complex data, or perform specific tasks that require custom logic not supported by standard form controls.
Why This Integration Matters
Understanding how to embed Canvas Apps is a critical skill for any Power Platform developer. It allows you to build "hybrid" applications that leverage the best of both platforms. By embedding a Canvas App, you can:
- Create Custom Visualizations: Display data in charts, maps, or galleries that go beyond the limitations of standard Model-Driven components.
- Implement Complex Logic: Run custom Power Fx formulas or connect to external data sources that are not natively available within the Model-Driven environment.
- Improve User Experience: Design task-specific interfaces that guide the user through a process, making complex data entry tasks much simpler and less prone to error.
- Extend Functionality: Add buttons or interactive elements that trigger flows, update multiple records at once, or perform calculations that aren't possible with standard form fields.
In this lesson, we will explore the technical requirements, the step-by-step implementation process, best practices for performance, and common pitfalls you should avoid to ensure your hybrid apps remain stable and maintainable.
Technical Prerequisites and Setup
Before you dive into embedding your first app, it is important to understand the underlying mechanics. When you embed a Canvas App, you are essentially placing an iframe-like container on your Model-Driven form. This container communicates with the form via a specific integration object called ModelDrivenFormIntegration.
This object is the key to the entire integration. It acts as the "bridge," passing the context of the current record (the ID, field values, etc.) from the Model-Driven form into the Canvas App. Without this object, the Canvas App would have no idea which record the user is currently looking at, rendering it useless for context-aware tasks.
The Integration Object Explained
When you create a Canvas App directly from the form designer, Power Apps automatically adds the ModelDrivenFormIntegration control to your app. This control provides the following properties:
- DataSource: The Dataverse table that the Model-Driven form is currently bound to.
- Item: A record object representing the current row in the Model-Driven form. You can reference properties like
ModelDrivenFormIntegration.Item.Nameto access data directly. - OnDataRefresh: A property that triggers logic when the Model-Driven form refreshes or saves, allowing you to update your Canvas App accordingly.
Callout: Canvas vs. Model-Driven Context It is vital to remember that a Canvas App embedded in a form is still a standalone app. It has its own environment, its own app-level settings, and its own performance profile. While it "lives" inside the Model-Driven form, it does not share the same session state as the form itself. Changes made in the Canvas App do not automatically update the Model-Driven form fields unless you explicitly trigger a save or refresh operation.
Step-by-Step: Embedding a Canvas App
Follow these steps to create your first embedded experience. We will assume you are working within a solution in the Power Apps maker portal.
1. Prepare the Model-Driven Form
Open the table you are working with and navigate to the "Forms" tab. Select the main form where you want to embed the custom functionality. Ensure that you have identified the specific section or tab where the Canvas App will reside.
2. Add the Canvas App Component
Inside the classic or modern form designer, look for the "Components" section. Select "Canvas app." You will be prompted to either create a new app or select an existing one. If you are starting fresh, choose "Create new."
3. Configure the Integration
When you click "Create," Power Apps will open the Canvas App editor in a new tab. You will notice that a control named ModelDrivenFormIntegration is already present on the screen. Do not delete this control! It is the foundation of the integration.
4. Designing the Interface
Now, you can build your interface. For example, if you are building an app to manage "Project Tasks" for a "Project" record, you might add a Gallery control. Set the Items property of the gallery to filter tasks related to the current record:
Filter(
'Project Tasks',
'Project ID' = ModelDrivenFormIntegration.Item.'Project ID'
)
5. Saving and Publishing
Once your design is complete, save and publish the Canvas App. Return to the Model-Driven form designer, and you will see your app listed in the configuration panel. You can now adjust the height of the app to ensure it fits nicely within the form layout. Save and publish your form to see the changes in your Model-Driven App.
Best Practices for Performance and Maintenance
Embedding Canvas Apps can introduce performance overhead if not managed correctly. Because the Canvas App loads separately from the Model-Driven form, having too many embedded apps can significantly slow down the page load time.
Keep it Lean
Only embed Canvas Apps when absolutely necessary. If a standard subgrid or a business rule can achieve the same outcome, use the standard functionality. Standard components are optimized for the platform and will always perform better than custom embedded apps.
Optimize Data Retrieval
Avoid complex LookUp or Filter queries that involve multiple joins across large datasets within the OnStart property of your Canvas App. Instead, use the context provided by ModelDrivenFormIntegration.Item to fetch only the specific data you need for the current record.
Use Caching Wisely
If your app displays data that doesn't change frequently, consider using local variables or collections to store the data after the initial load. This prevents the app from making unnecessary API calls to the Dataverse every time the user navigates or interacts with the form.
Tip: Monitoring Performance Use the "Monitor" tool in the Power Apps studio to track the performance of your embedded app. This allows you to see how long data queries take and identify any bottlenecks in your logic that might be causing a sluggish user experience.
Common Pitfalls and How to Avoid Them
Even experienced developers encounter issues when embedding apps. Here are the most frequent mistakes and how to avoid them:
- Ignoring Form Context: A common error is forgetting that the Canvas App needs to react to changes in the Model-Driven form. If the user changes a field in the form, the Canvas App might not update automatically. Always use the
OnDataRefreshproperty of theModelDrivenFormIntegrationcontrol to re-fetch or clear data when the parent form saves. - Over-complicating the UI: Because you have total freedom in Canvas, it is easy to clutter the space. Stick to the design language of your Model-Driven App. Use standard fonts, colors, and spacing so the embedded app feels like a natural part of the form rather than a foreign object.
- Hardcoding IDs: Never hardcode record IDs or environment-specific values in your Canvas App. Always rely on the
ModelDrivenFormIntegration.Itemobject to get the context dynamically. This ensures that your app will function correctly across different environments (Development, Test, Production). - Not Testing Mobile Responsiveness: Model-Driven Apps are inherently responsive, but embedded Canvas Apps often have fixed dimensions. Test your form on both desktop and mobile devices to ensure the Canvas App doesn't get cut off or become unusable on smaller screens.
Advanced Scenarios: Communicating Back to the Form
One of the most powerful features of this integration is the ability for the Canvas App to "talk back" to the Model-Driven form. For example, you might want a button in your Canvas App to update a field on the parent record or trigger a save operation on the main form.
To save the parent record from the Canvas App, you can use the PowerApps.save() function within your button's OnSelect property:
// Example: Updating a parent record field and saving
Patch(
Projects,
ModelDrivenFormIntegration.Item,
{ 'Status': 'Completed' }
);
ModelDrivenFormIntegration.RefreshForm();
This code updates the current record in the Dataverse and then instructs the Model-Driven form to refresh itself, reflecting the changes made by the Canvas App. This creates a highly responsive, integrated experience for the user.
Handling Data Synchronization
When you update data from within a Canvas App, there is a slight delay before the Dataverse reflects that change. If you immediately call RefreshForm(), the form might reload before the data has finished committing. In such cases, consider using a short Wait() or providing visual feedback (like a loading spinner) to the user to manage expectations.
Comparison: Embedded Canvas App vs. Custom Pages
With the introduction of "Custom Pages" in Power Apps, many developers are confused about when to use an embedded Canvas App and when to use a Custom Page.
| Feature | Embedded Canvas App | Custom Page |
|---|---|---|
| Primary Use | Enhancing existing forms | Building new, full-page experiences |
| Location | Inside a form section | As a page in the site map or dialog |
| Data Context | Bound to a specific record | Can be standalone or record-bound |
| Navigation | Limited to the form section | Supports complex navigation |
| Layout | Fixed size within a form | Full-page responsive container |
Note: When to choose what? Use an embedded Canvas App when you need to add custom logic or UI to an existing form. Use Custom Pages when you want to build a new view or a multi-step wizard that acts as a standalone page within your Model-Driven App.
Security and Permissions
Security is handled at the Dataverse level. Even if you embed a Canvas App, the user must still have the appropriate security roles to read and write the underlying data. If a user does not have permission to view the records being queried by your Canvas App, they will see an error or an empty state, even if the app is visible on the form.
Always test your apps with users who have different security roles to ensure that your logic doesn't inadvertently expose data that the user shouldn't be able to see. You can use the User() function in Power Apps to hide or show specific controls based on the logged-in user's identity, providing an extra layer of interface-level security.
Troubleshooting Checklist
If your embedded Canvas App is not behaving as expected, run through this checklist:
- Is the Integration Control present? Ensure
ModelDrivenFormIntegrationis visible in the tree view. - Are Data Sources connected? Check the "Data" tab in the Canvas App editor to ensure all tables are correctly connected.
- Is the Form Published? Remember that changes in the Canvas App editor are not live until you save and publish the app and publish the Model-Driven form.
- Are you using the right context? Check that your filters are using
ModelDrivenFormIntegration.Itemrather than a hardcoded ID. - Are permissions correct? Verify that the user has the necessary Dataverse security roles to access the data displayed in the app.
- Is the browser blocking the app? Occasionally, browser security settings or extensions can interfere with the iframe. Try opening the app in an Incognito window to rule out browser-level issues.
Designing for the Future
As you build more embedded apps, start creating a library of "reusable components." Instead of building a custom gallery for every project, create a single, well-designed component that takes parameters (like the record ID or the data source) and drop that component into your forms. This approach significantly reduces maintenance effort and ensures a consistent look and feel across your entire organization.
Furthermore, keep an eye on Microsoft's release notes. The integration between Canvas and Model-Driven is a high-priority area for development. New features, such as improved communication methods or better performance handling, are added regularly. Staying informed will allow you to refactor your existing apps to take advantage of these improvements as they become available.
Key Takeaways
As we conclude this lesson, keep these fundamental principles in mind for all your future development work:
- The Bridge is Critical: The
ModelDrivenFormIntegrationobject is the only way to pass context from a Model-Driven record to a Canvas App. Always preserve this control. - Performance Over Pizazz: While you have the freedom to design anything, keep performance in mind. Excessive complexity in an embedded app will negatively impact the user's experience of the entire form.
- Context-Awareness: Always design your apps to be dynamic. They should react to the specific record currently being viewed, not just a static set of data.
- Use Standard Patterns: Align your Canvas App design with the Model-Driven App’s look and feel to ensure that the user doesn't feel like they are switching between two different applications.
- Always Test for Security: Never assume that hiding a control in the Canvas App equates to securing the data. Data-level security must always be enforced in the Dataverse.
- Refactor and Reuse: Build components that can be reused across different forms to minimize your maintenance burden and keep your apps consistent.
- Think "Hybrid": See the integration as a way to extend the power of the Dataverse, not as a way to bypass it. Use the strengths of both platforms to build solutions that are robust, scalable, and user-friendly.
By mastering the art of embedding Canvas Apps, you move from being a user of the Power Platform to an architect of custom, high-value business solutions. You are no longer limited by the standard form layouts, allowing you to deliver the exact experience your business users need to be successful. Take the time to experiment with the examples provided, practice the configuration steps, and always prioritize the user experience in your designs.
Enjoying the courses?
Everything stays free. Pro shows fewer ads, doubles your daily points limit so you progress twice as fast, and lets you read each lesson on one page.
- ✓ Fewer advertisements
- ✓ 2× daily points limit
- ✓ Distraction-free lessons