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. Web Resource and IFRAME controls are not returned by this method.
Xrm.Page.ui.getCurrentControl()
- Return Value
-
Type: ObjectExample: 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."); } };
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
11
Read Optimized
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."); } };
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: NumberExample: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); };
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: NumberExample: 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: NoneRemarks: 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.
Reference
Xrm.Page ReferenceXrm.Page.context
Xrm.Page.data.entity
Xrm.Page.ui.controls Collection
Xrm.Page.ui.navigation.items Collection
Xrm.Page.ui.formSelector
Xrm.Page.ui.tabs Collection
Concepts
Form Scripting Quick ReferenceWrite Code for Microsoft Dynamics CRM Forms
Use the Xrm.Page Object Model
Microsoft Dynamics CRM 2011
Send comments about this topic to Microsoft.
© 2013 Microsoft Corporation. All rights reserved.