This topic has not yet been rated - Rate this topic

Xrm.Page.ui

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.

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.


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

Go to top

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

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


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

Go to top

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.


showViewPortSize: function () {
 var viewPortDisplay = document.createElement("DIV");
 viewPortDisplay.style.position = "absolute";
 viewPortDisplay.style.width = "150px";
 viewPortDisplay.style.height = "20px";
 viewPortDisplay.style.right = "0px";
 viewPortDisplay.style.bottom = "0px";
 viewPortDisplay.style.border = "1px solid black";
 viewPortDisplay.style.backgroundColor = "white";

 document.body.appendChild(viewPortDisplay);
 window.attachEvent("onresize", function () {
  SDK.UISamples.updateViewPortSize(viewPortDisplay);
 });

 SDK.UISamples.updateViewPortSize(viewPortDisplay);
},

updateViewPortSize: function (viewPortDisplay) {
 var viewPortHeight = Xrm.Page.ui.getViewPortHeight();
 var viewPortWidth = Xrm.Page.ui.getViewPortWidth();

 viewPortDisplay.innerText = "Width: " + viewPortWidth + ", Height: " + viewPortHeight;
},

Go to top

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.

Go to top

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.

Go to top

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 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 Content Add
Annotations FAQ