在promise之后使用control.setDisabled()



我正在为Dynamics 365编写一些JS,它禁用(锁定)所选可编辑子网格行的字段。

这样做的方法是.setDisabled()(Documentation)。我可以运行以下方法,在选择一行时锁定所有字段:

function onGridRowSelected(context){
context.data.entity.attributes.forEach(function (attr) {
attr.controls.forEach(function (myField) {
myField.setDisabled(foundResponse);
})
});
}

我遇到的问题是试图运行上述承诺。我有下面的代码,将传递一个承诺的结果到我的禁用字段的方法:

var gridContext;
function onGridRowSelected(context){
gridContext = context.getFormContext();
//Retrieve the record we want to check the value on
Xrm.WebApi.retrieveMultipleRecords("ms_approvalquery", "?$select=ms_responsetext&$top=1&$orderby=createdon desc")
.then(result => disableOrEnableFields(result));
}

function disableOrEnableFields(result){
//Check if the record found has a ms_responsetext != null
var foundResponse = false
if (result.entities[0].ms_responsetext != null){
foundResponse = true;
}
//Either disable/enable all the row columns depending on the value retrieved from the above
gridContext.data.entity.attributes.forEach(function (attr) {
attr.controls.forEach(function (myField) {
myField.setDisabled(foundResponse);
})
});
}

在执行调试时,我可以看到myField.setDisabled(true);正在被调用,但没有发生任何事情。这是因为它在一个单独的线程上吗?我如何回到主线程与我的承诺的结果?

注意:使用Async/Await也不起作用-它给出相同的结果。

几天前我们有类似的问题,不幸的是Async/Await/promise调用不尊重网格控制,你将不得不通过旧的/经典的同步调用方式,然后它应该工作。如果这能解决你的问题,请告诉我。

最新更新