Xrm.Page.ui.tabs Collection

[Applies to: Microsoft Dynamics CRM 2011]

Xrm.Page.ui.tabs is a collection of all the tabs present on the page. This collection provides methods to retrieve or perform actions on each of the tabs on the page.

Examples shown are in the Sample: SDK.TabCollectionSamples.js library.

Methods

The table below lists all the methods of Xrm.Page.ui.tabs.

Method Description

forEach

Applies the action contained within a delegate function.

get

Returns one or more tabs depending on the arguments passed.

getLength

Returns the number of tabs in the collection.

forEach

Applies the action contained within a delegate function.

Xrm.Page.ui.tabs.forEach(
delegate function(tab, index)
)
  • Arguments
    Delegate function with parameters for tab and index.

Example: The SDK.TabCollectionSamples.listTabs function uses an anonymous function defined within the argument to display a message showing the tabs that contain the letter 'a' in their label.

SDK.TabCollectionSamples.listTabs = function () {
 var message = "The following tabs contains the letter 'a' in their label:\n";

 Xrm.Page.ui.tabs.forEach(function (tab, index) {
  var tabLabel = tab.getLabel();

  if (tabLabel.toLowerCase().indexOf('a') != -1) {
   message += "  \u2219 " + tabLabel + "\n";
  }
 });

 alert(message);
};

Example: The SDK.TabCollectionSamples.listTabs_Example2 function passes a reference to a function defined outside the argument to display a message showing the tabs that contain the letter 'a' in their label.

SDK.TabCollectionSamples.listTabs_Example2 = function () {
 window.message = "The following tabs contains the letter 'a' in their label:\n";

 Xrm.Page.ui.tabs.forEach(SDK.TabCollectionSamples.addTabToMessage);

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

SDK.TabCollectionSamples.addTabToMessage = function (tab, index) {
 var tabLabel = tab.getLabel();

 if (tabLabel.toLowerCase().indexOf('a') != -1) {
  window.message += "  \u2219 " + tabLabel + "\n";
 }
};

Methods

get

Returns one or more tabs depending on the arguments passed.

Xrm.Page.ui.tabs.get(
[String][Number][delegate function(tab, index)]
)
  • Arguments

    • None

      • Return Value All the tabs.
        Type: Array

        Example: The SDK.TabCollectionSamples.getFirstTab function gets the first tab by using two different overloads of the get() method, and compares them to ensure they are the same.

        SDK.TabCollectionSamples.getFirstTab = function () {
         var allTabs = Xrm.Page.ui.tabs.get();
         var firstTabByIndex = Xrm.Page.ui.tabs.get(0);
        
         if (allTabs[0] == firstTabByIndex) {
          alert("The first tab has the label '" + firstTabByIndex.getLabel() + "'.");
         }
         else {
          alert("An error has occurred:\n\nUnable to determine the label of the first tab.");
         }
        };
        
    • String

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

        Example: The SDK.TabCollectionSamples.doesTabExist alerts the user if there is a tab on the form with the name of the value passed in.

        SDK.TabCollectionSamples.doesTabExist = function (tabName) {
         var tab = Xrm.Page.ui.tabs.get(tabName);
         if (tab != null) {
          alert("The tab with the name '" + tabName + "' does exist on the form.  It has a label of '" + tab.getLabel() + "'.");
         }
         else {
          alert("No tab with the name '" + tabName + "' exists on the form.");
         }
        };
        
    • Number

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

        Example: See the SDK.TabCollectionSamples.getFirstTab function example above.

    • delegate function(tab, index)

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

        Example: See the following SDK.TabCollectionSamples.getFirstAndLastTab function sample under getLength.

Methods

getLength

Returns the number of tabs in the collection.

Xrm.Page.ui.tabs.getLength()
  • Return Value
    Type: Number

    Example: The SDK.TabCollectionSamples.getFirstAndLastTab displays the label of the first and last tab on the form.

    SDK.TabCollectionSamples.getFirstAndLastTab = function () {
     var tabsLength = Xrm.Page.ui.tabs.getLength();
    
     var message = "The first and last tab on the form are:\n";
     var firstAndLastTab = Xrm.Page.ui.tabs.get(function (tab, index) {
      return index == 0 || index == tabsLength - 1;
     });
    
     for (var i in firstAndLastTab) {
      message += "- " + firstAndLastTab[i].getLabel() + "\n";
     }
    
     alert(message);
    };
    

Methods

See Also

Tasks

Sample: SDK.TabCollectionSamples.js

Reference

Xrm.Page.ui

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.