Show/Hide Tab , Section and fields in Dynamics CRM

var tabName = "your_tab_name"; // Replace with the actual name of the tab
var tab = formContext.ui.tabs.get(tabName);

if (tab != null) {
  // To show the tab
  tab.setVisible(true);

  // To hide the tab
  // tab.setVisible(false);
}

In this code, formContext represents the context of the current form. You should have access to it within the appropriate event handler or function where you want to show or hide the tab.

Again, make sure to replace "your_tab_name" with the actual name of the tab you want to show or hide.


// Get the section object by its name
var sectionName = "your_section_name"; // Replace with the actual name of the section
var section = formContext.ui.tabs.get(tabName).sections.get(sectionName);

if (section != null) {
  // To show the section
  section.setVisible(true);

  // To hide the section
  // section.setVisible(false);
}

 In this code, you first specify the name of the section you want to show or hide by setting the sectionName variable. Then, you use the formContext.ui.tabs.get(tabName).sections.get(sectionName) method to retrieve the section object based on its name. If the section object is found (section != null), you can call the setVisible() method on the section object to either show or hide the section by passing true or false as the parameter.

Make sure to replace "your_section_name" with the actual name of the section you want to show or hide.

// Get the field object by its name
var fieldName = "your_field_name"; // Replace with the actual name of the field
var field = formContext.getAttribute(fieldName);

if (field != null) {
  // To make the field read-only
  field.controls.forEach(function (control) {
    control.setDisabled(true);
  });

  // To make the field editable
  // field.controls.forEach(function (control) {
  //   control.setDisabled(false);
  // });
}











In this code, you specify the name of the field you want to make read-only or editable by setting the fieldName variable. Then, you use the formContext.getAttribute(fieldName) method to retrieve the field object based on its name. If the field object is found (field != null), you can call the setDisabled() method on each control associated with the field to make it read-only or editable.

By default, a field can have multiple controls associated with it (e.g., a text box, a lookup field). The field.controls property returns an array of all the controls associated with the field, and you can iterate over them using a forEach loop.

To make the field read-only, you call control.setDisabled(true). To make the field editable, you can call control.setDisabled(false).

Remember to replace "your_field_name" with the actual logical name of the field you want to modify.

Comments

Popular posts from this blog

Upload Email Attachments To share point and Delete from Dynamics CRM Through Power Automate Flow - Power Automate

Top Interview Questions and Answers for Dynamics 365 Development and Customization

Create folder on share point Microsoft dynamics CRM with document Location By Power Automate