Update Main Form Instantly After Adding Subgrid Row in Model-Driven App
Image Source: Shutterstock.com
Model-Driven App
Feb 14, 2024 7:00 PM

Update Main Form Instantly After Adding Subgrid Row in Model-Driven App

by HubSite 365 about Linn Zaw Win [MVP]

Citizen DeveloperModel-Driven AppLearning Selection

Automatically Update Main Form on New Subgrid Entry in Model-Driven Apps

Key insights

Refreshing Main Form in Model-Driven Apps: This post outlines a method to automatically refresh the data on the main form whenever a new row is added to a child table from the subgrid using the Quick Create Form. This is essential for keeping data up-to-date in model-driven applications, especially when changes in the child table affect calculations or summaries displayed on the parent form.

  • To ensure the main form reflects changes made in a child table's subgrid, a function can be added to trigger when the subgrid is loaded or refreshed. This function can compare the current number of rows against a previous count and refresh the main form if they differ.

  • Initially, set a global variable to track the row count upon the subgrid's first load. This variable is updated each time the subgrid is refreshed, facilitating the comparison to determine if the main form needs refreshing.

  • Through the addOnLoad() event handler attached to the subgrid control, the designated function is called, utilizing the getTotalRecordCount() method to obtain the current number of rows, enabling the comparison with the global variable.

  • If the row count has changed upon the subgrid's refresh, the main form is refreshed using the data.refresh() method to ensure the updated data is reflected immediately, maintaining data integrity and accuracy across the application.

  • This solution is adaptable for performing additional operations beyond just refreshing the main form, offering flexibility for developers to enhance user experience in model-driven applications.

Maintaining Data Integrity in Model-Driven Apps

Ensuring that data displayed in model-driven applications remains accurate and up-to-date is a persistent challenge for developers. The dynamics of these applications often involve multiple related entities where changes in one part (e.g., a subgrid or child table) can impact the display or calculations on another part (e.g., the main form). The technique of refreshing the main form automatically when changes occur in a subgrid addresses this challenge directly. By keeping the displayed data consistent with the underlying database, developers can improve usability and user trust in the application. Adaptation of such methods also supports better decision-making processes for users, as they rely on the latest information presented in the app. It is a reflection of good practice in application development, emphasizing the importance of responsive design and user-centric interfaces. These considerations are key to developing efficient and effective model-driven applications that serve the needs of businesses and end-users alike.

Refresh Main Form When New Child Row is Added in Subgrid via Quick Create Form in Model-Driven App. This post will explain how you can refresh all the data of the main form when a new row is added to the child table. The user adds a new row by clicking on the + Add New button from the subgrid and adding it from the Quick Create Form of the child table.

When the user adds a new row to the child table from the subgrid and saves and closes the Quick Create Form, the subgrid is refreshed. Similarly, when the user deletes or deactivates a row, the subgrid refreshes. However, if there is a background process updating the parent row's data, the main form might not immediately reflect these changes, since only the subgrid is refreshed.

To ensure the main form is refreshed when there are changes to the subgrid, a function can be added. This function should be triggered when the subgrid control is loaded or refreshed. It will compare the number of rows before and after the update and refresh the main form if there's a difference.

Start by setting a global variable for the initial loading of the subgrid. You should initialize it with var gridRowCount = -1;

Then, add an event handler to the subgrid control using the addOnLoad() method in the form's OnLoad function. This will ensure the function is called both during the initial subgrid load and upon each refresh.

In the function, use getTotalRecordCount() of the subgrid control to update the global variable. If the row count changes, use data.refresh() to update the main form's data.

This solution allows the main form data to be refreshed dynamically, ensuring up-to-date information is displayed. Additionally, the triggered function can be used for other purposes like refreshing another subgrid or opening a custom page.

Note: This solution was inspired by discussions on the Model-Driven App forum.

Enhancing User Experience in Model-Driven Apps

Model-Driven Apps provide a dynamic and interactive platform for managing business processes in the Microsoft ecosystem. By enabling users to add and modify data in real-time, these apps ensure that the most current information is always available. Specifically, when changes are made to subgrids through Quick Create Forms, reflecting these updates in the main form is vital for maintaining data integrity and providing users with a seamless experience.

Utilizing JavaScript functions to trigger form refreshes upon modifications ensures that changes in subgrid data are accurately represented. This automated process enhances efficiency by removing the need for manual updates, which can be time-consuming and prone to error.

Moreover, this approach offers flexibility for developers to implement additional customizations, such as refreshing related subgrids or opening auxiliary interfaces, further augmenting the app's functionality. As a result, users enjoy a more cohesive and efficient workspace, contributing to streamlined operations and effective data management.

In conclusion, incorporating dynamic form refreshing mechanisms into Model-Driven Apps significantly benefits users and developers alike, embodying the adaptability and innovation that characterizes the Microsoft Power Platform.

Refreshing Main Form in Model-Driven App

This blog post outlines how to refresh the main form in a Model-Driven App after adding a new child row via the Quick Create Form in a subgrid. It aims to ensure that any updates in the child table, which might impact calculations or data shown on the main form, are reflected immediately. This becomes particularly useful when dealing with asynchronous background processes that calculate and update data on the parent form.

The proposed solution involves adding a function that is called whenever the subgrid control is loaded or refreshed. This function counts the number of rows currently in the subgrid and refreshes the main form if the row count has changed. This approach not only ensures that the main form data stays updated but also allows for additional operations, like refreshing other subgrids or opening new forms, to be implemented seamlessly.

  • Setting a global variable for initial subgrid load.

  • Adding an event handler to the subgrid control using addOnLoad method.

  • Using getTotalRecordCount to manage row counts and refreshing the main form with data.refresh when necessary.

The method outlined provides a robust way to keep the main form's data updated with changes from child tables, enhancing user experience and data accuracy in applications developed with these technologies. This technique was inspired by discussions and collaborative problem-solving within the developer community.

Expanding on Model-Driven Application Development

Model-Driven Apps provide a dynamic approach to application design, focusing on the higher-level abstraction of the model rather than the low-level implementation details. This design paradigm facilitates the rapid development of enterprise-level applications by automating basic UI, logic, and database interactions. In these apps, data consistency and real-time updates are critical, especially in complex forms with hierarchical data relationships.

The challenge of keeping a main form updated when child data changes is common in these applications. Given these apps' data-driven nature, ensuring accurate and current data display without manual refreshes enhances both the user experience and data integrity. This blog's solution leverages Microsoft Power Apps' capabilities, showing how developers can implement intelligent and responsive data refresh techniques in their applications.

By focusing on event-driven data updates, developers can create more intuitive and responsive applications. This approach not only streamlines data management but also opens the door to more sophisticated interconnected data handling processes, further leveraging the power of Model-Driven development. This strategy emphasizes the adaptability and efficiency of utilizing Model-Driven Apps in complex data ecosystems, demonstrating their potential in modern enterprise solutions.

Model-Driven App - Update Main Form Instantly After Adding Subgrid Row in Model-Driven App

Read the full article Refresh Main Form When New Child Row is Added in Subgrid via Quick Create Form in Model-Driven App

People also ask

"How do I refresh Subgrid?"

In situations where a record is incorporated or eliminated from the subgrid, or when the subgrid's refresh button is engaged, a refresh event for the subgrid will be initiated. Upon performing such actions, the function functionTriggerredgetOnSubgridRefresh() comes into play after each insertion or removal of a record from the subgrid.

"How do I add a quick create form to Subgrid?"

In order to streamline the process, it's essential to focus on a singular section within which the desired columns will be placed, facilitating the immediate creation of records directly from the subgrid.

"How do I refresh a form in D365?"

The process involves the refreshing of the current form or page within Dynamics 365 to ensure the latest data is displayed and interactions are up to date.

"How to refresh CRM form using JavaScript?"

Utilizing JavaScript, one can refresh a CRM Grid to ensure the data shown is current and reflects any recent changes made within the system.


Model-Driven App, Refresh Main Form, Child Row Added, Subgrid Update, Quick Create Form, Dynamics 365, CRM, Update Form View, Add New Record, Real-Time Update