Xrm.Page.ui.formSelector item methods

[Applies to: Microsoft Dynamics CRM 2011]

A form item represents a form that is available to a user because it is associated with a security role that the user is also associated to. Often there will be only one form, but when more than one form is available, these methods can be used to change the form the user is viewing.

noteNote
When you use the navigate method while unsaved changes exist, the user is prompted to save changes before the new form can be displayed. The Onload event occurs when the new form loads.

Examples shown here are in the Sample: SDK.FormItemSamples.js library.

The following table lists all the methods of roleForm.

 

Method Description

getId

Returns the GUID ID of the roleForm.

getLabel

Returns the label of the roleForm.

navigate

Opens the specified roleForm.

getId

Returns the GUID ID of the form item.

itemObj.getId()
Return Value
Type: String

Example: The SDK.FormItemSamples.getFormInformation function displays the current form item's id and label to the user.


SDK.FormItemSamples.getFormInformation = function () {
 var item = Xrm.Page.ui.formSelector.getCurrentItem();
 if (item != null) {
  var itemId = item.getId();
  var itemLabel = item.getLabel();

  alert("The current form item has the following properties:\n\n" +
        "  \u2219 Label: '" + itemLabel + "'\n  \u2219 Id: '" + itemId + "'");
 }
 else {
  alert("The getFormInformation function only applies to forms with multiple form items.");
 }
};

Methods

getLabel

Returns the label of the roleForm.

itemObj.getLabel()
Return Value
Type:String

Example:See SDK.FormItemSamples.getFormInformation under getId.

Methods

navigate

Opens the specified roleForm.

itemObj.navigate()

Example:The SDK.FormItemSamples.showFormItems function displays a page in a new window showing the form items with a button to navigate to the form item.


SDK.FormItemSamples.showFormItems = function () {
 var items = Xrm.Page.ui.formSelector.items.get();
 if (items.length > 1) {
  var html = "<!DOCTYPE html ><html lang='en-US' ><head><title>Show Form Items</title>";
  html += "<style type=\"text/css\">body { font-family:Calibri;}";
  html += "table {border:1px solid gray; border-collapse:collapse;}";
  html += "th {text-align:left; border:1px solid gray;}";
  html += "td {border:1px solid gray;}</style>";
  html += "<script type=\"text/javascript\" >";
  html += "function navigate(itemId) { ";
  html += "window.opener.Xrm.Page.ui.formSelector.items.get(itemId).navigate(); ";
  html += "window.close();";
  html += "}";
  html += "</script></head><body>";
  html += SDK.FormItemSamples.getFormItems();
  html += "</body></html>";
  var myWindow = window.open("", "_blank", "height=400,width=350,scrollbars=1,resizable=1", false);
  myWindow.document.open();
  myWindow.document.write(html);
  myWindow.document.close();
 }
 else {
  alert("There is only one form item currently available.");
 }
};

SDK.FormItemSamples.getFormItems = function () {
 var html = "<table summary='This table displays a row for each form item containing a button to navigate to that form.'><thead><tr><th scope='col'>Form Item Label</th><th></th>" +
    "</tr></thead><tbody>";
 var items = Xrm.Page.ui.formSelector.items.get();
 var currentFormId = Xrm.Page.ui.formSelector.getCurrentItem().getId();
 for (var i in items) {
  var item = items[i];
  var itemId = item.getId();
  if (itemId != currentFormId) {
   var itemLabel = item.getLabel();
   html += "<tr><td>" + itemLabel +
            "</td><td><input type=\"button\" onclick=\"navigate('" + itemId +
            "');\" value='Navigate to " + itemLabel + "' /></td></tr>";
  }

 }

 html += "</tbody></table>";
 return html;
};

Methods

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

Community Additions

ADD
Show: