javascript - 无法让 setValue 在 Dynamics CRM 可编辑网格上工作

标签 javascript dynamics-crm dynamics-crm-365

我希望得到一些关于如何在 Dynamics CRM 365(内部部署)可编辑网格中执行 setValue 的指示:

无论我尝试什么,我都无法更新网格中的值。此代码获取属性的引用,但 setValue 似乎对网格没有影响。

    function updateDocsOK(ctlName, grdName, attributeName) {
    var selectedRow = null;
    var attributeColl = null;
    var twoOptionValue = 0;


    try {

        //This is the Yes/No value in the dropdown
        var ctlValue = Xrm.Page.getAttribute(ctlName).getValue();
        if (ctlValue) {
            twoOptionValue = 1;
        }
        //get the selected rows - use the getControl method and pass the grid name.
        selectedRow = Xrm.Page.getControl(grdName).getGrid().getRows();

        //loop through rows and get the attribute collection
        selectedRow.forEach(function (row, rowIndex) {


            var att = row.getData().getEntity().attributes.getByName(attributeName);

            //This setValue does not work on a two-option
            if (att) {
                console.log(att.getValue());
                att.setValue(twoOptionValue);
                console.log(att.getValue());
            }


            //This setValue does not work on a text field
            att = row.getData().getEntity().attributes.getByName("new_testtext");

            if (att) {
                att.setValue("hello");
            }


        });
    } catch (e) {
        Xrm.Utility.alertDialog(e.message);
    }
}

最佳答案

您应该选择传递执行上下文的选项,并使用 executionContext.getFormContext() 获取可编辑网格中的当前行。

function updateDocsOK(executionContext) {
    var entityObject = executionContext.getFormContext().data.entity;
    var att = entityObject.attributes.getByName("new_testtext");
    att.setValue("hello");
 }

you can’t use Xrm.Page commands on editable grids. In my example I’ll want to set the probability value.

On the form something like Xrm.Page.getAttribute(“closeprobability”).setValue(80) would do the trick. But this won’t work on editable grids.

Instead I need to use a new method that has been released with Dynamics 365 (getFormContext).

getFormContext returns a reference for either the form (Xrm.Page) or the editable grid (GridRow). Meaning we can now have code that will work in both situations.

Read more

关于javascript - 无法让 setValue 在 Dynamics CRM 可编辑网格上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50258737/

相关文章:

javascript - Ajax 中的 URL open()

javascript - Dynamics crm 2016 - Web API 查询 - 动态值

dynamics-crm - 我可以使用 FetchXML 检索实体列表和属性列表吗?

dynamics-crm - 此错误是什么意思 "The ' RetrieveMultiple' 方法不支持 Dynamics CRM/api/data/<version> 中类型为“的实体”?

c# - 如何在 Dynamics 365 中以编程方式获取营业时间详细信息

c# - 客户端脚本无需查询字符串即可工作

javascript - 使用 PHP 变量作为 JavaScript 函数的参数

javascript - 如何根据查询字符串参数将元素标记为选中

c# - 在电话实体的描述中包含超链接

c# - 更新自定义工作流程事件中创建的记录 -CRM -C#