Disable column in Dynamics CRM editable subgrid based on a condition

时光怂恿深爱的人放手 提交于 2020-04-16 04:13:05

问题


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.

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

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

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


回答1:


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

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

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.

Reference

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

Read more



来源:https://stackoverflow.com/questions/57687304/disable-column-in-dynamics-crm-editable-subgrid-based-on-a-condition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!