【发布时间】:2021-12-07 22:49:46
【问题描述】:
你好我做了一个函数来检测我是否在我的子网格中添加或删除了一个新行并根据它执行一些 coce
通常它在现有父记录中可以正常工作,除非我创建一个新的父记录,然后按保存,然后在子网格中添加一行并且我的函数由于某种原因执行两次
有谁知道为什么我的代码只在我创建新的父记录时才执行两次,该函数甚至在 onLoad 中
我从这里获取了原理代码:(dsomething 函数触发了两次)
function onLoad() {
var funtionName = "onLoad";
try {
setTimeout(function () {
if (Xrm.Page != null && Xrm.Page != undefined && Xrm.Page.getControl("contact_subgrid") != null && Xrm.Page.getControl("contact_subgrid") != undefined) {
_rowCount = Xrm.Page.getControl("subgrid").getGrid().getTotalRecordCount();
Xrm.Page.getControl("subgrid").addOnLoad(onGridLoad);
}
}, 5000);
} catch (e) {
Xrm.Utility.alertDialog(functionName + "Error: " + (e.message || e.description));
}
}
function onGridLoad() {
var functionName = " onGridLoad ";
var currentRowCount = null;
try {
setTimeout(function () {
if (Xrm.Page != null && Xrm.Page != undefined && Xrm.Page.getControl("contact_subgrid") != null && Xrm.Page.getControl("contact_subgrid") != undefined) {
currentRowCount = Xrm.Page.getControl("subgrid").getGrid().getTotalRecordCount();
if (currentRowCount > _rowCount) {
dosomething();
_rowCount = currentRowCount;
}
else if (currentRowCount < _rowCount) {
dosomethingelse();
_rowCount = currentRowCount;
}
}
}, 2000);
} catch (e) {
Xrm.Utility.alertDialog(functionName + "Error: " + (e.message || e.description));
}
}
【问题讨论】:
标签: javascript dynamics-crm microsoft-dynamics powerapps dynamics-crm-online