Xrm.Page.ui.formSelector item methods

Switch View :
ScriptFree
Xrm.Page.ui.formSelector item methods

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.

Methods

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.

JScript
itemObj.getId()
Return Value
Type: String

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

JScript

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.");
    }
},

Go to top

getLabel

Returns the label of the roleForm.

JScript
itemObj.getLabel()
Return Value
Type:String

Example:See SDK.FormItemSamples.getFormInformation under getId.

Go to top

navigate

Opens the specified roleForm.

JScript
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.

JScript

showFormItems: function ()
{
    var items = Xrm.Page.ui.formSelector.items.get();
    if (items.length > 1)
    {
        var html = "<html><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/jscript\" >";
        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");
        myWindow.document.open();
        myWindow.document.write(html);
        myWindow.document.close();
    }
    else
    {
        alert("There is only one form item currently available.");
    }
},

getFormItems: function ()
{
    var html = "<table><thead><th>Form Item Label</th><th></th>" +
"</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;
}

Go to top

See Also

Reference

Xrm.Page.ui.formSelector.items Collection
Xrm.Page.ui.formSelector

Other Resources

Sample: SDK.FormItemSamples.js

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