Xrm.Page.ui tab.sections Collection

[Applies to: Microsoft Dynamics CRM 2011]

The sections collection contains all the sections present within a tab. This collection implements the collection methods to retrieve or perform actions on each of the sections within the tab.

Examples shown below are in the Sample: SDK.TabSamples.js library.

Methods

The following table lists all the methods of a sections collection.

Method Description

forEach

Applies the action contained within a delegate function.

get

Returns one or more sections depending on the arguments passed.

getLength

Returns the number of sections in the collection.

forEach

Applies the action contained within a delegate function.

tabObj.sections.forEach(delegate function(section, index))
  • Arguments
    Delegate function with parameters for section and index.
  • Return Value
     

Example: The SDK.TabSamples.listFormHierarchy function uses an anonymous function defined within the argument to display a message showing the hierarchy of tabs and sections on the current form.

SDK.TabSamples.listFormHierarchy = function () {
 var tabs = Xrm.Page.ui.tabs.get();

 var message = "The hierarchy of the current form is:\n\n";

 for (var i in tabs) {
  var tab = tabs[i];

  message += "  \u2219 " + tab.getLabel() + "\n";

  tab.sections.forEach(function (section, sectionIndex) {
   var sectionLabel = section.getLabel();
   if (sectionLabel == null) {
    sectionLabel = "No Section Label Defined";
   }

   message += "      \u2219 " + sectionLabel + "\n";
  });
 }

 alert(message);
};

Example: The SDK.TabSamples.listFormHierarchy_Example2 function passes a reference to a function defined outside the argument to display a message showing the hierarchy of tabs and sections on the current form.

SDK.TabSamples.listFormHierarchy_Example2 = function () {
 var tabs = Xrm.Page.ui.tabs.get();

 window.message = "The hierarchy of the current form is:\n\n";

 for (var i in tabs) {
  var tab = tabs[i];

  window.message += "  \u2219 " + tab.getLabel() + "\n";

  tab.sections.forEach(SDK.TabSamples.listSectionName);
 }

 alert(window.message);
 window.message = null;
};

SDK.TabSamples.listSectionName = function (section, index) {
 var sectionLabel = section.getLabel();
 if (sectionLabel == null) {
  sectionLabel = "No Section Label Defined";
 }

 window.message += "      \u2219 " + sectionLabel + "\n";
};

Methods

get

Returns one or more sections depending on the arguments passed.

tabObj.sections.get([String][Number][delegate function(attribute, index)])
  • Arguments

    • None

      • Return Value All the sections within the tab.
        Type: Array

        Example: The SDK.TabSamples.showSectionLabels function loops through all of the sections in the first tab and display their label.

        SDK.TabSamples.showSectionLabels = function () {
         var firstTabSections = Xrm.Page.ui.tabs.get(0).sections.get();
        
         var message = "The following sections are in the first tab on the form:\n\n";
         for (var i in firstTabSections) {
          var sectionLabel = firstTabSections[i].getLabel();
          if (sectionLabel == null) {
           sectionLabel = "No Section Label Defined";
          }
        
          message += "  \u2219 " + sectionLabel + "\n";
         }
        
         alert(message);
        };
        
    • String

      • Return Value The section within the tab where the name matches the argument.
        Type: Object

        Example: The SDK.TabSamples.doesSectionExistByName displays whether there is a section with the given name on the form.

        SDK.TabSamples.doesSectionExistByName = function (sectionName) {
         var tabs = Xrm.Page.ui.tabs.get();
         var sectionCount = 0;
        
         for (var i in tabs) {
          var tab = tabs[i];
        
          var section = tab.sections.get(sectionName);
          if (section != null) {
           sectionCount++;
          }
         }
        
         alert("There are " + sectionCount + " section(s) on the form with the name '" + sectionName + "'.");
        };
        
    • Number

      • Return Value The section in the tab where the index matches the number.
        Type: Object

        Example: The SDK.TabSamples.showFirstSectionPerTab function displays the name of the first section in every tab.

        SDK.TabSamples.showFirstSectionPerTab = function () {
         var tabs = Xrm.Page.ui.tabs.get();
        
         var message = "The first sections in every tabs are:\n\n";
        
         for (var i in tabs) {
          var tab = tabs[i];
          var firstSection = tab.sections.get(0);
          var sectionLabel = firstSection.getLabel();
          if (sectionLabel == null) {
           sectionLabel = "No Section Label Defined";
          }
        
          message += "  \u2219 " + sectionLabel + "\n";
         }
        
         alert(message);
        };
        
    • delegate function(section, index)

      • Return Value Any sections that cause the delegate function to return true.
        Type: Array

        Example: The SDK.TabSamples.showSectionsVisibility function shows the visibility of every section on the form.

        SDK.TabSamples.showSectionsVisibility = function () {
         var tabs = Xrm.Page.ui.tabs.get();
         var message = "The following is a list of tabs and their display state:\n\n";
        
         for (var i in tabs) {
          var tab = tabs[i];
        
          tab.sections.get(function (section, index) {
           var sectionLabel = section.getLabel();
           if (sectionLabel == null) {
            sectionLabel = "No Section Label Defined";
           }
        
           var visibility = "";
           if (section.getVisible()) {
            visibility = "Visible";
           }
           else {
            visibility = "Hidden";
           }
        
           message += "  \u2219 " + sectionLabel + " - " + visibility + "\n";
          });
         }
        
         alert(message);
        };
        

Methods

getLength

Returns the number of sections in the collection.

tabObj.sections.getLength()
  • Return Value
    Type: Number

    Example: The SDK.TabSamples.listMultipleSectionTabs function lists every tab that contains two or more sections.

    SDK.TabSamples.listMultipleSectionTabs = function () {
     var tabs = Xrm.Page.ui.tabs.get();
    
     var message = "The following tab(s) contain multiple sections:\n\n";
    
     for (var i in tabs) {
      var tab = tabs[i];
    
      var sectionsCount = tab.sections.getLength();
      if (sectionsCount > 1) {
       message += "  \u2219 " + tab.getLabel() + "\n";
      }
     }
    
     alert(message);
    };
    

Methods

See Also

Tasks

Sample: SDK.TabSamples.js

Concepts

Form Scripting Quick Reference
Write Code for Microsoft Dynamics CRM Forms
Use the Xrm.Page Object Model

Microsoft Dynamics CRM 2011
Send comments about this topic to Microsoft.
© 2013 Microsoft Corporation. All rights reserved.