使用control.setDisabled()

发布于 2025-02-13 07:31:01 字数 1664 浏览 1 评论 0原文

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

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

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);被调用,但没有发生任何事情。这是因为它在单独的线程上吗?我如何根据自己的诺言回到主线程?

注意:使用异步/等待也不起作用 - 它给出相同的结果。

I'm writing some JS for Dynamics 365 which disables (locks) the fields on the selected editable subgrid row.

The method to do this is .setDisabled() (Documentation). I can run the following method which will lock all the fields upon selecting a row:

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

The issue I am having is trying to run the above following a promise. I have the following code which will pass the result of a promise into my disable fields methods:

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

When stepping through debug, I can see that myField.setDisabled(true); is getting called but nothing is happening. Is this because it's on a separate thread? How do I get back to the main thread with the result of my promise?

Note: Using Async/Await doesn't work either - it gives the same results.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

草莓味的萝莉 2025-02-20 07:31:01

几天前,我们也遇到了类似的问题,不幸的是,异步/等待/承诺电话不尊重网格控制,您将必须按照旧/经典的同步通话方式进行操作,然后它可以工作。让我知道这是否解决了您的问题。

we had similar issues few days back, unfortunately Async/Await/promise call does not respect grid control, you will have to go by old/classic Sync call way and then it shall work. Let me know if this solves your problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文