简体   繁体   English

根据条件禁用 Dynamics CRM 可编辑子网格中的列

[英]Disable column in Dynamics CRM editable subgrid based on a condition

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

I need to disable (make read-only) a column from an editable subgrid in a Dynamics CRM 365 form.我需要从 Dynamics CRM 365 表单中的可编辑子网格中禁用(设为只读)列。

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:在 MS 文档( https://docs.microsoft.com/en-us/previous-versions/dynamicscrm-2016/developers-guide/mt788311(v=crm.8) 中,完成此操作的方法是通过使用:

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

but the problem is that controls array is always null, so I cannot disable the column (apply setDisable function on control)但问题是控件数组始终为空,因此我无法禁用该列(在控件上应用setDisable函数)

In IE console, the expression Xrm.Page.getControl("Opportunity_Installments").getGrid().getRows().getAll()[0].getData().entity.attributes.getAll()[0].controls returns null.在 IE 控制台中,表达式Xrm.Page.getControl("Opportunity_Installments").getGrid().getRows().getAll()[0].getData().entity.attributes.getAll()[0].controls返回 null .

Most important thing : Xrm.Page is deprecated, you have to start using context.getFormContext() .最重要的是Xrm.Page已弃用,您必须开始使用context.getFormContext()

Unfortunately the editable grid controls & internal things are not totally rendered on form load, we have to rely on OnRowSelect event.不幸的是,可编辑的网格控件和内部事物并没有完全在表单加载时呈现,我们必须依赖OnRowSelect事件。

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.在可编辑网格中选择记录后,Dynamics 365 会在内部评估一系列内容,包括用户对记录的访问权限、记录是否处于活动状态以及字段验证,以确保在您编辑数据时遵守数据安全性和有效性。 Consider using the OnRecordSelect event with the getFormContext method to access records in the grid that are in the editable state.考虑使用 OnRecordSelect 事件和 getFormContext 方法来访问网格中处于可编辑状态的记录。

Reference 参考

The workaround (available solution) is to use below snippet on OnRowSelect event.解决方法(可用的解决方案)是在OnRowSelect事件上使用以下代码段。

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

Read more 阅读更多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 dynamics crm在关联的视图上获取子网格的名称 - dynamics crm get name of subgrid on associated view 动态CRM。 在subgrid中完全自定义FetchXml - Dynamics CRM. Fully custom FetchXml in subgrid 如何以Dynamics CRM形式调整子网格的高度? - How to resize the height of the subgrid in dynamics crm forms? 如何在Dynamics CRM 2016中基于表单禁用功能区按钮? - How to disable ribbon button based on Form in Dynamics CRM 2016? 在 Dynamics 365 CRM 统一界面中重新加载/刷新子网格时重新加载表单 - Reload Form on reload/refresh of subgrid in Dynamics 365 CRM Unified Interface MS Dynamics CRM 2013子网格与其添加按钮重叠 - Ms dynamics crm 2013 subgrid overlap with its add button Dynamics CRM 2011获取子网格选定的单元格值 - Dynamics crm 2011 get subgrid selected cell value 将工具提示添加到Dynamics 365中子网格中的列名称 - Add tooltip to column name in a subgrid in Dynamics 365 设置子网格的fetchXML时,无法读取Dynamics CRM中未定义的属性“ SetParameter” - Cannot read property 'SetParameter' of undefined in Dynamics CRM while setting up fetchXML of a subgrid Dynamics CRM - 从子网格创建记录时的 N:N 关系数据/字段/属性映射 - Dynamics CRM - N:N relationship data/field/attribute mapping when creating record from subgrid
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM