Skip to main content

Notifications

Announcements

No record found.

Show and Hide Fields, Sections and Tabs in Dynamics 365 JavaScript

Introduction

Xrm-ex simplifies the process of controlling the visibility, interactivity, and required status of fields, tabs, and sections. This guide dives straight into practical examples of how to efficiently manage these elements.

Prerequisites

  • You have set up xrm-ex according to this guide: A Guide to Simplify Dynamics 365 JavaScript Development using xrm-ex
  • You have fields defined in your xrm-ex model, similar to this:
    •     class Fields {
              CompanyName = new XrmEx.Class.TextField("companyname");
              Street1 = new XrmEx.Class.TextField("address1_line1");
              City = new XrmEx.Class.TextField("address1_city");
              Country = new XrmEx.Class.TextField("address1_country");
          }
             class Tabs {
              General = new XrmEx.Class.Tab("tab1", {
                  Section1: new XrmEx.Class.Section("section1"),
              });
          }
             var fields = new Fields();
             var tabs = new Tabs();

Managing Individual Fields with xrm-ex

Show/Hide, Enable/Disable, and Set Required
fields.CompanyName.setVisible(true); // Show field
fields.CompanyName.setVisible(false); // Hide field
fields.CompanyName.setDisabled(true); // Disable field
fields.CompanyName.setRequired(true); // Make field required

// Chain multiple actions for efficiency
fields.CompanyName.setVisible(true).setDisabled(false).setRequired(true);

Managing Tabs and Sections

Show/Hide Tabs
tabs.General.setVisible(true);  // Show the tab
tabs.General.setVisible(false); // Hide the tab

Show/Hide Sections
tabs.General.Section.Section1.setVisible(true);  // Show the section
tabs.General.Section.Section1.setVisible(false); // Hide the section

Bulk Operations on Fields

Apply Changes to Multiple Fields
var companyFields = [fields.CompanyName, fields.Street1, fields.City, fields.Country];
//You can set all these fields to visible and enabled with just a few lines of code:
XrmEx.Fields.setVisible(companyFields, true);  // Show all fields
XrmEx.Fields.setDisabled(companyFields, false); // Enable all fields

Summary of Key Points

  • Fields: Use .setVisible(), .setDisabled(), .setRequired() for granular control.
  • Tabs/Sections: Manage visibility with .setVisible().
  • Bulk Operations: Use XrmEx.Fields for efficient handling of multiple field

Conclusion

With xrm-ex, controlling fields, tabs, and sections is concise, readable, and maintainable. The library's intuitive API minimizes repetitive code, making it ideal for creating dynamic, user-focused forms in Dynamics 365.


Comments