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?
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);
Hi bp3378,
Maybe you can refer the following link:
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,101 Super User 2024 Season 2
Martin Dráb 229,908 Most Valuable Professional
nmaenpaa 101,156