根据条件在Dynamics CRM可编辑子网格中禁用列 [英] Disable column in Dynamics CRM editable subgrid based on a condition

查看:287
本文介绍了根据条件在Dynamics CRM可编辑子网格中禁用列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于条件禁用 Dynamics CRM 可编辑子网格中的列

Disable column in Dynamics CRM editable subgrid based on a condition

我需要禁用(设为只读)

I need to disable (make read-only) a column from an editable subgrid in a Dynamics CRM 365 form.

在MS doc中( https://docs.microsoft.com/zh-CN/previous-versions/dynamicscrm-2016/developers-guide /mt788311(v=crm.8),完成此操作的方法是使用以下控件:

In MS doc (https://docs.microsoft.com/en-us/previous-versions/dynamicscrm-2016/developers-guide/mt788311(v=crm.8), the way to get this done is by getting controls with:

Xrm.Page.getControl("Opportunity_Installments").getGrid().getRows().getAll()[0].getData().entity.attributes.getAll()[0].controls

,但问题是控件数组始终为空,因此我无法禁用该列(应用 setDisable 控制功能)

but the problem is that controls array is always null, so I cannot disable the column (apply setDisable function on control)

在IE控制台中,表达式 Xrm.Page.getControl( Opportunity_Installments)。getGrid()。 getRows()。getAll()[0] .getData()。en tity.attributes.getAll()[0] .controls 返回null。

In IE console, the expression Xrm.Page.getControl("Opportunity_Installments").getGrid().getRows().getAll()[0].getData().entity.attributes.getAll()[0].controls returns null.

推荐答案

最重要的事情:已弃用 Xrm.Page ,您必须开始使用 context.getFormContext()

Most important thing: Xrm.Page is deprecated, you have to start using context.getFormContext().

不幸的是,可编辑网格控件&内部事物并不能完全在表单加载时呈现,我们必须依靠 OnRowSelect event。

Unfortunately the editable grid controls & internal things are not totally rendered on form load, we have to rely on OnRowSelectevent.


出于性能原因,在选择记录之前,可编辑网格中的行(记录)不可编辑。用户必须在网格中选择一个记录才能对其进行编辑。一旦在可编辑网格中选择了一条记录,Dynamics 365就会在内部评估一堆内容,包括用户对该记录的访问权限,该记录是否处于活动状态以及字段验证,以确保在编辑数据时尊重数据安全性和有效性。考虑将OnRecordSelect事件与getFormContext方法一起使用以访问网格中处于可编辑状态的记录。

For performance reasons, a row (record) in an editable grid is not editable until the record is selected. Users must select a single record in a grid to edit it. Once a record is selected in an editable grid, Dynamics 365 internally evaluates a bunch of things including user access to the record, whether the record is active, and field validations to ensure that data security and validity are honored when you edit data. Consider using the OnRecordSelect event with the getFormContext method to access records in the grid that are in the editable state.

参考

解决方法(可用的解决方案)是在 OnRowSelect 事件的代码段下方使用。

The workaround (available solution) is to use below snippet on OnRowSelect event.

function gridRowSelected(context) {
    context.getFormContext().getData().getEntity().attributes.forEach(function (attr) {
        if (attr.getName() === "new_fieldname") {
            attr.controls.forEach(function (c) {
                c.setDisabled(true);
            })
        }
    });
}

了解详情

这篇关于根据条件在Dynamics CRM可编辑子网格中禁用列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆