Skip to main content

Notifications

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

subgrid record deletion does not refresh page

Posted on by 190

I have a subgrid i have JS code that loads every time the subgrid is supposedly refreshed by adding, deleting record.  When i add record in the subgrid, it fires up the code and enables the field in the main form. But when i delete the record in the subgrid, it disables the field but the form does not refresh so the field still shows as enabled unless i manually hit refresh on the form.  Why does it not refresh on deletion?  

I am using the gridContext.addOnLoad(loadFunction) function and i thought this should work for deletions as well. 

What can I do to fix this?

  • Suggested answer
    lunamiffy Profile Picture
    lunamiffy 15 on at
    RE: subgrid record deletion does not refresh page

          hi, I met the same problem last week. And now I fixed it. the same part of our problem is the main form didn't refresh after deletion of the records in subgrid. So I added a function on the OnSave event to add a subgrid onload function. The function in the loading of subgrid was created to record the number of the records after deletion. And I added a function on the OnRecordSelect event to record the initial number of the records. If you do so, now you can compare the two numbers. if the current one less than the initial one, you can refresh the main form manually and update the initial one using the current one. If you have any questions about above, please feel free to contact me.

    var MainTest_Form = window.MainTest_Form || {};
    (function () {
        //记录明细行初始总条数
        var initRowCount = 0;
    
        /**
         * 子网格删除记录时 刷新整个网格
         * */
    
        this.onGridLoad = function (primaryContext) {
            if (Xrm.Page.getControl("subgrid_InBounddetail") != undefined && Xrm.Page.getControl("subgrid_InBounddetail") != null) {
                //添加子网格加载函数
                Xrm.Page.getControl("subgrid_InBounddetail").addOnLoad(this.onSubgridLoad);
            }
        }
    
        this.onSubgridRowSelected = function () {
            //记录明细行初始总条数
            initRowCount = Xrm.Page.getControl("subgrid_InBounddetail").getGrid().getTotalRecordCount();
        }
    
        this.onSubgridLoad = function (primaryContext) {
            var curRowCount = 0;
            if (Xrm.Page.getControl("subgrid_InBounddetail") != undefined && Xrm.Page.getControl("subgrid_InBounddetail") != null) {
                //记录明细行当前条数
                curRowCount = Xrm.Page.getControl("subgrid_InBounddetail").getGrid().getTotalRecordCount();
                //若删除了记录
                if (curRowCount < initRowCount) {
                    //刷新整个网格的数据
                    primaryContext.getFormContext().data.refresh(true);
                    //删除记录后 更新初始总条数
                    initRowCount = curRowCount;
                }
            }
    
        }
    }).call(MainTest_Form);

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: subgrid record deletion does not refresh page

    Hi bp3378,

    Maybe you can refer the following link: 

    Identify the trigger for an On-load event for Sub-grid in Dynamics CRM | Microsoft Dynamics 365 CRM Tips and Tricks (inogic.com)

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,101 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,908 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans