[英]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 方法来访问网格中处于可编辑状态的记录。
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);
})
}
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.