Thursday, 26 December 2019

Refresh Parent form if a record is added or deleted from the subgrid

Hello Eveyone,

We had a requirement to refresh the main form if a record is added or removed from the subgrid. To achieve this we have written following javascript on load of the main form.
Declared global variable _rowcount to capture grid row count on form load and then comparing the count on load of the grid.

var _rowcount = 0;
function onLoad(executionContext) {
    var formContext = executionContext.getFormContext(); // get the form context
    var gridContext = formContext.getControl("Contacts_grid");// get the grid context
    //stores the row count of subgrid on load event of CRM Form
    _rowcount = gridContext.getGrid().getTotalRecordCount();
    gridContext.addOnLoad(myContactsGridOnloadFunction);

}
function myContactsGridOnloadFunction(executionContext) {
    var currentRowCount = null;
    var formContext = executionContext.getFormContext();
    currentRowCount = formContext.formContext.getControl("Contacts_grid").getGrid().getTotalRecordCount();
    if (currentRowCount != _rowcount) {
        _rowcount = currentRowCount;
        formContext.formContext.data.refresh();
    }
};      
 

No comments:

Post a Comment