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

Announcements

No record found.

News and Announcements icon
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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
Pallavi Phade Profile Picture

Pallavi Phade 102 Super User 2026 Season 1

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 55 Super User 2026 Season 1

#3
ManoVerse Profile Picture

ManoVerse 53 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans