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 |
|---|---|
| Closes the form. | |
| Returns the control object that currently has focus on the form. | |
| Indicates the form context for the record. | |
| Returns the height of the viewport in pixels. | |
| Returns the width of the viewport in pixels. | |
| 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.
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.
Example: The SDK.UISamples.getFormType alerts the user with a different message depending on the current form type.Value Form Type 0
Undefined
1
Create
2
Update
3
Read Only
4
Disabled
5
Quick Create (Deprecated)
6
Bulk Edit
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."); } },
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; },
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.
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.
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.
Send comments about this topic to Microsoft.
© 2012 Microsoft Corporation. All rights reserved.