When working with PowerApps Model-Driven Apps, you might need to add a Custom Page to a form.
Recently, someone in a WhatsApp group I’m a part of asked for help:
How can I implement the following in a PowerApps model-driven app? I have a case form and want to add a custom page that, upon loading, retrieves all task records associated with a specific case entity. These tasks should be displayed in a grid, and when I select a task from the grid, I need to edit that task record. Could you provide some insight?
To fetch tasks on page load, I was using Power Fx in the OnVisible property of the custom page.
// Get the Case ID from the navigation context
Set(varCaseID, Param("recordId"));
// Fetch all task records related to this case
ClearCollect(
colTasks,
Filter(Tasks, RegardingId = varCaseID)
);
Filtering wasn’t working, so I tested with LookUp to check if the Case ID was being retrieved correctly.
Set(
varSingleTask,
LookUp(Tasks, 'Regarding (Case)'.IncidentId = varCaseID)
);
LookUp did not work either. This is where ModelDrivenFormIntegration comes into play. It acts as a bridge between custom pages and model-driven forms, allowing seamless data transfer and interaction.
What is ModelDrivenFormIntegration?
ModelDrivenFormIntegration is a special PowerApps control that provides contextual information about the form it is embedded in. It helps retrieve form data, interact with records, and update values dynamically within a custom page.
What Does ModelDrivenFormIntegration Do?
- Passes data from the model-driven form to a custom page
- Provides access to the currently selected record in the form
- Allows actions like saving, refreshing, or updating records
Key Properties
| Property | Description |
|---|---|
Item |
The record currently being viewed/edited |
DataSource |
The table (Dataverse entity) the form is bound to |
Mode |
The current form mode (Edit, New, View) |
How to use it in Power Fx
Get Current Record's ID (Primary Key)
ModelDrivenFormIntegration.Item.'IncidentId'
This retrieves the Case ID (IncidentId) from the form. It is useful when filtering related records like tasks or logs.
Get a Field Value from the Current Record
ModelDrivenFormIntegration.Item.Title
This gets the Title field of the current record. Replace Title with any other field name from your entity.
Filter Related Records in a Custom Page
Filter('Tasks', 'Case'.'IncidentId' = ModelDrivenFormIntegration.Item.'IncidentId')
This expression fetches all Case Logs that are linked to the current Case shown in the form.
Check If Form is in Edit or New Mode
If(ModelDrivenFormIntegration.Mode = FormMode.New, "New Record", "Existing Record")
This helps customize behavior based on whether a user is creating a new record or editing an existing one.
Advanced Use Cases
1. Conditional Formatting Based on Data
Use Power Fx to highlight fields based on conditions:
If(ModelDrivenFormIntegration.Item.Status = "Pending", RGBA(255,0,0,1), RGBA(0,255,0,1))
This changes the background color based on the record’s Status field.
2. Trigger a Flow When a Button is Clicked
If you want to run a Power Automate Flow, add a button and use:
PowerAutomateFlow.Run(ModelDrivenFormIntegration.Item.ID)
Replace PowerAutomateFlow with your actual Flow name.
When Should You Use ModelDrivenFormIntegration?
- Passing data to custom pages from a Model-Driven Form
- Filtering related records dynamically based on the selected form record
- Checking form mode for different user actions
Conclusion
Using ModelDrivenFormIntegration, you can deeply integrate Custom Pages with Model-Driven Apps, unlocking powerful capabilities. Whether it's reading form data, modifying fields, or triggering actions, this feature ensures your custom solutions work seamlessly within Dataverse environments.
💡 Next Steps: See my other blog where i have added a custom page to a Model-Driven App Table (entity) form! 🚀
Happy PowerApp-ing! 🎉
No comments:
Post a Comment