Enable/Disable the field placed in multiple places on the form

Hi Everyone,

Today I was writing JavaScript code to disable the field on some condition and observed that the field is not getting disabled. I was little surprised and tried with some other field and it worked perfectly. By this, I understand that there is some problem with this field and after some search understood that the same field has been placed on other tabs as well.

To fix it, we just have apply loop through the control. Here is the sample code for the same.

formContext.getAttribute("SchemaName").controls.forEach(
function (control, i) {
control.setDisabled(true);
});

Hope this helps.


Happy 365’ing
Gopinath.

Hide Formselector on the Form – Dynamics 365 CE/CRM

Hi Everyone,

Today I got a requirement to hide FormSelector on the Form as Users would have access to multiple forms but we have to navigate them to right form based on a field value on the record and we shouldn’t give an option to change the form to the User.

My initial thought was it’s not possible to hide formselector but one of my colleagues came up with the below piece of the code and it worked like a charm.

Logic is simple, set Visibility of the forms to False.

 var formContext = executionContext.getFormContext();
    formContext.ui.formSelector.items.get().forEach(function (item, index) {
        // hide all the form apart from Opportunity.
        if (item.getLabel() != "Opportunity") {
            item.setVisible(false);
        }
    });

Without above code, we see formselector

With code, we don’t see formselector

Hope this helps.


Happy 365’ing
Gopinath