Xrm.Page.ui

[Applies to: Microsoft Dynamics CRM 2011]

Xrm.Page.ui contains methods to retrieve information about the user interface as well as collections for several subcomponents of the form.

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

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

 

Method Description

close

Closes the form.

getCurrentControl

Returns the control object that currently has focus on the form.

getFormType

Indicates the form context for the record.

getViewPortHeight

Returns the height of the viewport in pixels.

getViewPortWidth

Returns the width of the viewport in pixels.

refreshRibbon

Causes the ribbon to re-evaluate data that controls what is displayed in it.

close

Closes the form.

Xrm.Page.ui.close()

Remarks: The HTML Window.close method is suppressed. To close a form window you must use this method. If there are any unsaved changes in the form the user will be prompted whether they want to save their changes before the window closes.

getCurrentControl

Returns the control object that currently has focus on the form. Web Resource and IFRAME controls are not returned by this method.

Xrm.Page.ui.getCurrentControl()
Return Value
Type: Object

Example: The SDK.UISamples.getCurrentControl function alerts the user with the name of the attribute that currently has focus on the form.


SDK.UISamples.getCurrentControl = function () {
 var currentControl = Xrm.Page.ui.getCurrentControl();
 if (currentControl == null) {
  alert("No controls currently have focus.");
 }
 else {
  alert("The control for the '" + currentControl.getLabel() + "' attribute currently has focus.");
 }
};

Methods

getFormType

Indicates the form context for the record.

Xrm.Page.ui.getFormType()
Return Value
Type: Number

The following table lists the form types that correspond to the return value.

 

Value Form Type

0

Undefined

1

Create

2

Update

3

Read Only

4

Disabled

5

Quick Create (Deprecated)

6

Bulk Edit

11

Read Optimized

Example: The SDK.UISamples.getFormType alerts the user with a different message depending on the current form type.


SDK.UISamples.getFormType = function () {

 var FORM_TYPE_CREATE = 1;
 var FORM_TYPE_UPDATE = 2;
 var FORM_TYPE_READ_ONLY = 3;
 var FORM_TYPE_DISABLED = 4;
 var FORM_TYPE_QUICK_CREATE = 5;
 var FORM_TYPE_BULK_EDIT = 6;
 var FORM_TYPE_READ_OPTIMIZED = 11;

 var formType = Xrm.Page.ui.getFormType();
 if (formType == FORM_TYPE_CREATE) {
  alert("This record has not yet been created.");
 }
 else {
  alert("This record exists in the database.");
 }
};

Methods

getViewPortHeight

Returns the height of the viewport in pixels.

Xrm.Page.ui.getViewPortHeight()

Remarks: The ViewPort is the area of the page containing form data. It corresponds to the body of the form and does not include the navigation, header, footer or form assistant areas of the page.

Return Value
Type: Number

Example:The SDK.UISamples.showViewPortSize function displays the current view port width and height to the user in the bottom right corner of the screen as the window is resized.


SDK.UISamples.showViewPortSize = function () {
 var viewPortHeight = Xrm.Page.ui.getViewPortHeight();
 var viewPortWidth = Xrm.Page.ui.getViewPortWidth();
 alert("Width: " + viewPortWidth + ", Height: " + viewPortHeight);
};

Methods

getViewPortWidth

Returns the width of the viewport in pixels.

Xrm.Page.ui.getViewPortWidth()

Remarks: The ViewPort is the area of the page containing form data. It corresponds to the body of the form and does not include the navigation, header, footer or form assistant areas of the page.

Return Value
Type: Number

Example: See the example for getViewPortHeight using SDK.UISamples.showViewPortSize.

Methods

refreshRibbon

Causes the ribbon to re-evaluate data that controls how it is displayed.

Xrm.Page.ui.refreshRibbon()
Return Value
Type: None

Remarks: This function is typically used when a ribbon <EnableRule> (RibbonDiffXml) depends on a value in the form. After your code changes a value that is used by a rule, use this method to force the ribbon to re-evaluate the data in the form so that the rule can be applied.

Methods

Xrm.Page.ui provides access to the following collections:

Xrm.Page.ui.controls Collection
A collection of all the controls on the page.

Xrm.Page.ui.navigation.items Collection
A collection of all the navigation items on the page.

Xrm.Page.ui.formSelector
A collection containing information about all the forms available for the user.

Xrm.Page.ui.tabs Collection
A collection of all the tabs on the page.

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

Community Additions

ADD
Show: