Export (0) Print
Expand All

Xrm.Page.ui.formSelector.items Collection

[Applies to: Microsoft Dynamics CRM 2011]

Xrm.Page.ui.formSelector.items is a collection of all the forms available for the user. Only those forms that share an association with one of the user’s security roles are available in this collection. This collection provides methods to retrieve or perform actions on each of the forms.

noteNote
When there is only one form available the Xrm.Page.ui.formSelector.items Collection is empty and the getCurrentItem method will return null.

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

This table lists the methods of the Xrm.Page.ui.formSelector.items collection.

 

Method Description

forEach

Applies the action contained within a delegate function.

get

Returns one or more roleForms depending on the arguments passed.

getLength

Returns the number of roleForms in the collection.

forEach

Applies the action contained within a delegate function.

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

Example:The SDK.FormSelectorSamples.listFormItems function uses an anonymous function defined within the argument to display a message showing the label of every form item.


SDK.FormSelectorSamples.listFormItems = function () {
 var message = "The following form items are available:\n";

 Xrm.Page.ui.formSelector.items.forEach(function (item, index) {
  var itemLabel = item.getLabel();
  message += "  \u2219 " + itemLabel + "\n";
 });

 alert(message);
};

Example:The SDK.FormSelectorSamples.listFormItems_Example2 function passes a reference to a function defined outside the argument to display a message showing the label of every form item.


SDK.FormSelectorSamples.listFormItems_Example2 = function () {
 window.message = "The following form items are available:\n";

 Xrm.Page.ui.formSelector.items.forEach(SDK.FormSelectorSamples.addFormItemToMessage);

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

SDK.FormSelectorSamples.addFormItemToMessage = function (item, index) {
 var itemLabel = item.getLabel();
 window.message += "  \u2219 " + itemLabel + "\n";
};

Methods

get

Returns one or more items depending on the arguments passed.

Xrm.Page.ui.formSelector.items.get(
[String][Number][delegate function(item, index)]
)
Arguments
None
Return Value All the items.
Type: Array

String
Return Value The item where the name matches the argument.
Type: Object

Number
Return Value The item where the index matches the number
Type: Object

delegate function(item, index)
Return Value Any items that cause the delegate function to return true.
Type: Array

Example:The SDK.FormSelectorSamples.getFirstFormItem function gets the first form item using all four of the get() overloads, and compares them to ensure they are the same.


SDK.FormSelectorSamples.getFirstFormItem = function () {
 var allItems = Xrm.Page.ui.formSelector.items.get();

 if (allItems.length > 1) {
  // Get the first form item by index.
  var firstItemByIndex = Xrm.Page.ui.formSelector.items.get(0);

  // Get the first form item by id.
  var firstItemByName = Xrm.Page.ui.formSelector.items.get(firstItemByIndex.getId());

  // Get the first form item by using a delegate function.
  // When using a delegate function, the return value is an array,
  // so assign firstItemByDelegateFunction to the first item in the resulting array.
  var firstItemByDelegateFunction = Xrm.Page.ui.formSelector.items.get(function (item, index) {
   return index == 0;
  })[0];

  if (allItems[0] == firstItemByIndex &&
            firstItemByIndex == firstItemByName &&
            firstItemByName == firstItemByDelegateFunction) {
   alert("The first form navigation item has the label '" + firstItemByName.getLabel() + "'.");
  }
  else {
   alert("An error has occurred:\n\nUnable to determine the label of the first form navigation item.");
  }
 }
 else {
  alert("There is only one form item currently available.");
 }
};

Methods

getLength

Returns the number of items in the collection.

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

Example:The SDK.FormSelectorSamples.showFormItemsCount function displays the count of the form items.


SDK.FormSelectorSamples.showFormItemsCount = function () {
 var items = Xrm.Page.ui.formSelector.items.get();
 var count = Xrm.Page.ui.formSelector.items.getLength();

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

Methods

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

Community Additions

Show:
© 2014 Microsoft