Prvá časť zo série Microsoft Dynamics CRM – Javascript API zaoberajúca sa prácou s kontrolkami resp. vlastnosťami entít – in english for search engines.
The CRM javascript API for manipulation with the controls is represented by namespace called Xrm.Page. The control object provides methods to change the presentation or behavior of a control and identify the corresponding attribute. You can access controls using the following collections: Xrm.Page.ui.controls, but the most usefull shortcut method to access the specific control/attribute is Xrm.Page.getControl(‘attributeName’) method. Under the selected control, you can use folowing methods (we are specifiing only most common/usefull methods; full specification you can find on msdn network):
1. Disabled - Enable or disable the control:
Xrm.Page.getControl('attributeName').setDisabled(bool)
2. Attribute - Returns the particular attribute value – usefull for lookup attribute :
Xrm.Page.getControl('attributeName').getAttribute()
3. Label - Get or change the label for a control using the getLabel and setLabel methods.
Xrm.Page.getControl('attributeName').getLabel()
Xrm.Page.getControl('attributeName').setLabel(label)
4. Notification - Use setNotification to display a notification about the control and clearNotification to remove it. Display a message near the control to indicate that data isn’t valid. When this method is used on Microsoft Dynamics CRM for tablets a red "X" icon appears next to the control. Tapping on the icon will display the message.
Xrm.Page.getControl('attributeName').setNotification(message, messageId)
Xrm.Page.getControl('attributeName').clearNotification(messageId)
5. OptionSet - Use the addOption, clearOptions, and removeOption methods to manipulate options available for OptionSet controls.
Xrm.Page.getControl('attributeName').addOption(option, [index])
Option is little object with text and value properties.
Xrm.Page.getControl('attributeName').clearOptions()
Xrm.Page.getControl('attributeName').removeOption(option.value)
6. Refresh - Refreshes the data displayed in a subgrid.
Xrm.Page.getControl('attributeName').refresh()
7. Focus - Sets the focus on the control.
Xrm.Page.getControl('attributeName').setFocus()
8. Time - specify whether a date control should show the time portion of the date.
Xrm.Page.getControl('attributeName').setShowTime(bool)
9. Visible - Determine which controls are visible and show or hide them using the getVisible and setVisible methods.
Xrm.Page.getControl('attributeName').setVisible(bool)
10. IFrame - Use these methods to interact with web resource and IFRAME controls.
Xrm.Page.getControl('subGridName').getData()
Returns the value of the data query string parameter passed to a Silverlight web resource.
Xrm.Page.getControl('subGridName').setData(string)
Sets the value of the data query string parameter passed to a Silverlight web resource.
Xrm.Page.getControl('subGridName').setSrc(string)
Sets the URL to be displayed in an IFRAME or web resource.
Little tip to the end: If you want to manipulate with control in the header of the form, specify prefix “header_” before property name. Example : Xrm.Page.getControl(‘header_attributeName’).