This topic has not yet been rated - Rate this topic

Xrm.Page.ui.navigation.items Collection

[Applies to: Microsoft Dynamics CRM 2011 and Microsoft Dynamics CRM Online]

Xrm.Page.ui.navigation.items is a collection of all the navigation options present on the left side of the page. This collection provides methods to retrieve or perform actions on each of the navigation items.

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

The following table lists the methods of Xrm.Page.ui.navigation.items.

 

Method Description

forEach

Applies the action contained within a delegate function.

get

Returns one or more navigation items depending on the arguments passed.

getLength

Returns the number of navigation items in the collection.

forEach

Applies the action contained within a delegate function.

Xrm.Page.ui.navigation.items.forEach(delegate function(item, index))
Arguments
Delegate function with parameters for item and index.

Return Value
Type: String

Example:The SDK.NavItemsCollectionSamples.listNavItems function uses an anonymous function defined within the argument.to display a filtered list of Navigation items.


SDK.NavItemsCollectionSamples.listNavItems = function () {
 var message = "The following navigation items contains the letter 'a' in their label:\n";

 Xrm.Page.ui.navigation.items.forEach(function (item, index) {
  var itemLabel = item.getLabel();

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

 alert(message);
};
Example:The SDK.NavItemsCollectionSamples.listNavItems_Example2 function passes a reference to a function defined outside the argument to display a filtered list of Navigation items.


SDK.NavItemsCollectionSamples.listNavItems_Example2 = function () {
 window.message = "The following navigation items contains the letter 'a' in their label:\n";

 Xrm.Page.ui.navigation.items.forEach(SDK.NavItemsCollectionSamples.addNavItemToMessage);

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

SDK.NavItemsCollectionSamples.addNavItemToMessage = function (item, index) {
 var itemLabel = item.getLabel();

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

Methods

get

Returns one or more navigation items depending on the arguments passed.

Xrm.Page.ui.navigation.items.get([String][Number][delegate function(attribute, index)])
noteNote
The name of the navigation item does not correspond to the name of the entity relationships it may display.

Arguments
None
Return Value All the navigation items.
Type: Array

Example:The SDK.NavItemsCollectionSamples.listNavItemsWithTheLetterS function displays a message showing the navigation items that contain the letter 's' in their label.


SDK.NavItemsCollectionSamples.listNavItemsWithTheLetterS = function () {
 var message = "The following navigation items contains the letter 's' in their label:\n";
 var items = Xrm.Page.ui.navigation.items.get();

 for (var i in items) {
  var item = items[i];
  var itemLabel = item.getLabel();
  if (itemLabel.toLowerCase().indexOf('s') != -1) {
   message += "  \u2219 " + itemLabel + "\n";
  }
 }

 alert(message);
};
String
Return Value The navigation item where the name matches the argument.
Type: Object

Example: The SDK.NavItemsCollectionSamples.doesActivityItemExist function displays a message stating if there is a navigation item with an id of 'navActivities'.


SDK.NavItemsCollectionSamples.doesActivityItemExist = function () {
 var activityItem = Xrm.Page.ui.navigation.items.get("navActivities");
 if (activityItem != null) {
  alert("The '" + activityItem.getLabel() + "' item does exist in this form's navigation area.");
 }
 else {
  alert("The 'Activities' item does not exist in this form's navigation area.");
 }
};
Number
Return Value The item where the index matches the number
Type: Object

Example: The SDK.NavItemsCollectionSamples.listFirstActivityItem function displays the first navigation item's label.


SDK.NavItemsCollectionSamples.listFirstActivityItem = function () {
 var firstItem = Xrm.Page.ui.navigation.items.get(0);
 if (firstItem != null) {
  alert("The first navigation item is '" + firstItem.getLabel() + "'.");
 }
 else {
  alert("There are not currently any navigation items on the form.");
 }
};
delegate function(attribute, index)
Return Value Any navigation items that cause the delegate function to return true.
Type: Array

Example: The SDK.NavItemsCollectionSamples.listEveryOtherNavItem function displays a message showing the navigation items that contain the letter 'a' in their label.


SDK.NavItemsCollectionSamples.listEveryOtherNavItem = function () {
 var message = "The following list is the label of every other navigation item on the form:\n";
 var items = Xrm.Page.ui.navigation.items.get(function (item, index) {
  return index % 2 == 0;
 });

 for (var i in items) {
  message += "  \u2219 " + items[i].getLabel() + "\n";
 }

 alert(message);
};

Methods

getLength

Returns the number of navigation items in the collection.

Xrm.Page.ui.navigation.items.getLength()
Return Value
Type: Number

Example:The SDK.NavItemsCollectionSamples.showNavItemsCount function displays the count of the navigation items on the form.


SDK.NavItemsCollectionSamples.showNavItemsCount = function () {
 var items = Xrm.Page.ui.navigation.items.get();
 var count = Xrm.Page.ui.navigation.items.getLength();

 if (items.length == count) {
  alert("There are " + count + " navigation item(s) on the form.");
 }
 else {
  alert("An error has occurred:\n\nUnable to determine how many navigation items are on the form.");
 }
};

Methods

Microsoft Dynamics CRM 2011 and Microsoft Dynamics CRM Online
Send comments about this topic to Microsoft.
© 2012 Microsoft Corporation. All rights reserved.
Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.