web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

subgrid record deletion does not refresh page

(0) ShareShare
ReportReport
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?

I have the same question (0)
  • Community Member Profile Picture
    on at

    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)

  • Suggested answer
    lunamiffy Profile Picture
    15 on at

          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);

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Siv Sagar Profile Picture

Siv Sagar 93 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 76

#3
Martin Dráb Profile Picture

Martin Dráb 66 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans