Xrm.Page.ui Control Methods
The control object provides methods to change the presentation of a control and identify the corresponding attribute.
Examples shown are in the Sample: SDK.ControlSamples.js library.
The following table lists the methods of control objects.
| Method | Description |
|---|---|
|
Adds a new view for the lookup dialog. Control Types: Lookup |
|
|
Adds an option to an Option set control. Control Types: Option Set |
|
|
Clears all options from an Option Set control. Control Types: Option Set |
|
|
Returns the attribute that the control is bound to. Control Types: Standard, Lookup, OptionSet |
|
|
Returns a value that categorizes controls. Control Types: All |
|
|
Returns the value of the data query string parameter passed to a Silverlight web resource. For more information, see setData. Control Types: Silverlight web resources. |
|
|
Returns the ID value of the default lookup dialog view. For more information, see setDefaultView. Control Types: Lookup |
|
|
Returns a value that indicates whether the control is disabled. For more information, see setDisabled. Control Types: All except web resources and subgrid. |
|
|
Returns the label for the control. See also setLabel Control Types: All |
|
|
Returns the name assigned to the control. Control Types: All |
|
|
Returns a reference to the section object that contains the control. Control Types: All |
|
|
Returns the current URL being displayed in an IFrame. See also setSrc Control Types: IFrame, web resource |
|
|
Returns the default URL that an IFrame control is configured to display. Control Types: IFrame |
|
|
Returns the object in the form representing an IFrame or web resource. Control Types: IFrame, web resource |
|
|
Returns a value that indicates whether the control is currently visible. For more information, see setVisible. Control Types: All |
|
|
Refreshes the data displayed in a subgrid. Control Types: Subgrid |
|
|
Removes an option from an Option Set control. Control Types: Option Sets |
|
|
Sets the value of the data query string parameter passed to a Silverlight web resource. For more information, see getData. Control Types: Silverlight web resources. |
|
|
Sets the default view for the lookup control dialog box. For more information, see getDefaultView. Control Types: Lookup |
|
|
Sets a value that indicates whether the control is disabled. See also getDisabled Control Types: All except web resources and subgrid. |
|
|
Sets the focus on the control. Control Types: All |
|
|
Sets the label for the control. For more information, see getLabel. Control Types: All |
|
|
Sets the URL to be displayed in an IFrame. See also getSrc Control Types: IFrame and web resource |
|
|
Sets a value that indicates whether the control is visible. For more information, see getVisible. Control Types: All |
addCustomView
Adds a new view for the lookup dialog box.
controlObj.addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, isDefault)
- Remarks
- This method does not work with Owner lookups. Owner lookups are used to assign user-owned records.
- Arguments
-
- viewId
-
String: The string representation of a GUID for a view.
Note This value is never saved and only needs to be unique among the other available views for the lookup. A string for a non-valid GUID will work, for example “{00000000-0000-0000-0000-000000000001}”. It is recommended that you use a tool like guidgen.exe to generate a valid GUID. The guidgen.exe tool is included in the Windows SDK.
- entityName
- String: The name of the entity.
- viewDisplayName
- String: The name of the view.
- fetchXml
- String: The fetchXml query for the view.
- layoutXml
- String: The XML that defines the layout of the view.
- isDefault
- Boolean: Whether the view should be the default view.
Example:The SDK.ControlSamples.addCustomView function will add a new custom lookup called “SDK Sample View” to any lookup on the form that has a default view that shows account records.
SDK.ControlSamples.addCustomView = function () { // Most of the code in this example is simply to look for any account lookups in a given form. // Actually setting the custom view is done in the SDK.ControlSamples.setCustomViewOnAccountLookup function below. var lookupControls = Xrm.Page.ui.controls.get(SDK.ControlSamples.isLookup); for (var i in lookupControls) { SDK.ControlSamples.processLookup(lookupControls[i]); } }; SDK.ControlSamples.isLookup = function (control, index) { return control.getControlType() == "lookup"; }; SDK.ControlSamples.processLookup = function (lookupControl) { //Is this a lookup for the account entity? // Retrieve the lookup attribute and check the Targets property. var currentEntity = Xrm.Page.data.entity.getEntityName(); var LookupAttributeName = lookupControl.getAttribute().getName(); //Use the SOAP endpoint var request = ["<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Body>", "<Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">", "<request i:type=\"a:RetrieveAttributeRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\">", "<a:Parameters xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">", "<a:KeyValuePairOfstringanyType>", "<b:key>EntityLogicalName</b:key>", "<b:value i:type=\"c:string\" xmlns:c=\"http://www.w3.org/2001/XMLSchema\">" + currentEntity + "</b:value>", "</a:KeyValuePairOfstringanyType>", "<a:KeyValuePairOfstringanyType>", "<b:key>MetadataId</b:key>", "<b:value i:type=\"ser:guid\" xmlns:ser=\"http://schemas.microsoft.com/2003/10/Serialization/\">00000000-0000-0000-0000-000000000000</b:value>", "</a:KeyValuePairOfstringanyType>", "<a:KeyValuePairOfstringanyType>", "<b:key>RetrieveAsIfPublished</b:key>", "<b:value i:type=\"c:boolean\" xmlns:c=\"http://www.w3.org/2001/XMLSchema\">false</b:value>", "</a:KeyValuePairOfstringanyType>", "<a:KeyValuePairOfstringanyType>", "<b:key>LogicalName</b:key>", "<b:value i:type=\"c:string\" xmlns:c=\"http://www.w3.org/2001/XMLSchema\">" + LookupAttributeName + "</b:value>", "</a:KeyValuePairOfstringanyType>", "</a:Parameters>", "<a:RequestId i:nil=\"true\" /><a:RequestName>RetrieveAttribute</a:RequestName></request>", "</Execute>", "</soapenv:Body></soapenv:Envelope>"]; var req = new XMLHttpRequest(); var serverUrl = Xrm.Page.context.getServerUrl(); if (serverUrl.match(/\/$/)) { serverUrl = serverUrl.substring(0, serverUrl.length - 1); } req.open("POST", serverUrl + "/XRMServices/2011/Organization.svc/web", true); try { req.responseType = 'msxml-document' } catch (e) { } req.setRequestHeader("Accept", "application/xml, text/xml, */*"); req.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute"); req.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { try { this.onreadystatechange = null; //avoids memory leaks SDK.ControlSamples.setSelectionNameSpaces(this.responseXML); } catch (e) { } if (SDK.ControlSamples.isAccountLookup(this)) { SDK.ControlSamples.setCustomViewOnAccountLookup(lookupControl); } } }; req.send(request.join("")); }; SDK.ControlSamples.setSelectionNameSpaces = function(doc) { var namespaces = [ "xmlns='http://schemas.microsoft.com/xrm/2011/Contracts/Services'", "xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'", "xmlns:a='http://schemas.microsoft.com/xrm/2011/Contracts'", "xmlns:i='http://www.w3.org/2001/XMLSchema-instance'", "xmlns:c='http://schemas.microsoft.com/xrm/2011/Metadata'", "xmlns:d='http://schemas.microsoft.com/2003/10/Serialization/Arrays'", "xmlns:b='http://schemas.datacontract.org/2004/07/System.Collections.Generic'" ]; doc.setProperty("SelectionNamespaces", namespaces.join(" ")); } SDK.ControlSamples.isAccountLookup = function (resp) { var targets = null; var returnValue = false; // Verify that the lookup attribute is for the account // The Targets property should only contain a single node with the values 'account'. if (typeof resp.responseXML.selectSingleNode != 'undefined') { //For IE targets = resp.responseXML.selectSingleNode("//c:Targets"); if (targets.childNodes.length == 1 && targets.firstChild.text == "account") { returnValue = true; } } else if (typeof resp.responseXML.evaluate != 'undefined') { // For other browsers var nsResolver = function (prefix) { var ns = { "default": "http://schemas.microsoft.com/xrm/2011/Contracts/Services", "s": "http://schemas.xmlsoap.org/soap/envelope/", "a": "http://schemas.microsoft.com/xrm/2011/Contracts", "i": "http://www.w3.org/2001/XMLSchema-instance", "c": "http://schemas.microsoft.com/xrm/2011/Metadata", "d": "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "b": "http://schemas.datacontract.org/2004/07/System.Collections.Generic" }; if (prefix == null || prefix == "") { return ns["default"]; } else { if (ns[prefix] == null) { return null; } else { return ns[prefix]; } } }; targets = resp.responseXML.evaluate("//c:Targets", resp.responseXML, nsResolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; if (targets.childNodes.length == 1 && targets.firstChild.textContent == "account") { returnValue = true; } } return returnValue; }; SDK.ControlSamples.setCustomViewOnAccountLookup = function (lookupControl) { var viewId = "{C7034F4F-6F92-4DD7-BD9D-9B9C1E996380}"; var viewDisplayName = "SDK Sample View"; var fetchXml = "<fetch version='1.0' " + "output-format='xml-platform' " + "mapping='logical'>" + "<entity name='account'>" + "<attribute name='name' />" + "<attribute name='address1_city' />" + "<order attribute='name' " + "descending='false' />" + "<filter type='and'>" + "<condition attribute='ownerid' " + "operator='eq-userid' />" + "<condition attribute='statecode' " + "operator='eq' " + "value='0' />" + "</filter>" + "<attribute name='primarycontactid' />" + "<attribute name='telephone1' />" + "<attribute name='accountid' />" + "<link-entity alias='accountprimarycontactidcontactcontactid' " + "name='contact' " + "from='contactid' " + "to='primarycontactid' " + "link-type='outer' " + "visible='false'>" + "<attribute name='emailaddress1' />" + "</link-entity>" + "</entity>" + "</fetch>"; var layoutXml = "<grid name='resultset' " + "object='1' " + "jump='name' " + "select='1' " + "icon='1' " + "preview='1'>" + "<row name='result' " + "id='accountid'>" + "<cell name='name' " + "width='300' />" + "<cell name='telephone1' " + "width='100' />" + "<cell name='address1_city' " + "width='100' />" + "<cell name='primarycontactid' " + "width='150' />" + "<cell name='accountprimarycontactidcontactcontactid.emailaddress1' " + "width='150' " + "disableSorting='1' />" + "</row>" + "</grid>"; try { lookupControl.addCustomView(viewId, "account", viewDisplayName, fetchXml, layoutXml, false); lookupControl.setDefaultView(viewId); alert("The '" + lookupControl.getName() + "' lookup was updated with a new default view.\n\nThe new view id is '" + lookupControl.getDefaultView() + "'."); } catch (e) { alert(e.message); } };
addOption
Adds an option to an option set control.
controlObj.addOption(option, [index])
Important |
|---|
| This method does not check that the values within the options you add are valid. You should only add options that have been defined for the specific option set control you are working with. |
- Arguments
-
- option
- Object: An option object to add to the OptionSet.
- index
- Number: (Optional) The index position to place the new option. If not provided the option will be added to the end.
Example:The SDK.ControlSamples.reverseOptions function reverses the order of all available options in the first option set control on the form.
SDK.ControlSamples.reverseOptions = function () { var optionsetControl = Xrm.Page.ui.controls.get(SDK.ControlSamples.isOptionSet)[0]; if (optionsetControl != null) { var options = optionsetControl.getAttribute().getOptions(); // Reverse all of the options in the optionset. optionsetControl.clearOptions(); for (var i = 1; i <= options.length; i++) { if (options[options.length - i].value != "null") { optionsetControl.addOption(options[options.length - i], i - 1); } } alert("The options for the " + optionsetControl.getLabel() + " field have been reversed."); } else { alert("There are no Option set controls in this form."); } }; SDK.ControlSamples.isOptionSet = function (control, index) { return control.getControlType() == "optionset"; };
clearOptions
Clears all options from an Option Set control.
controlObj.clearOptions()
Example: See the SDK.ControlSamples.reverseOptions function sample in addOption.
getAttribute
Returns the attribute that the control is bound to.
controlObj.getAttribute()
Note |
|---|
| Controls that are not bound to an attribute do not have this method. They will return error number -2146823281 with the error message: “'getAttribute()' is null or not an object”. |
- Return Value
- Type: Object: An attribute.Example:See the SDK.ControlSamples.reverseOptions function sample in addOption.
getControlType
Returns a value that categorizes controls.
controlObj.getControlType()
- Return Value
-
Type: String
Possible return values of getControlType:
Return Value Description standard
A Standard control.
iframe
An IFrame control
lookup
A Lookup control.
optionset
An OptionSet control
subgrid
A subgrid control
webresource
A web resource control
notes
A Notes control
Example: The SDK.ControlSamples.showControlTypes function will display a page in a new window showing the control type for every control on the form.
Note Before Microsoft Dynamics CRM 2011 Update Rollup 12 and Microsoft Dynamics CRM December 2012 Service Update notes controls returned standard. SDK.ControlSamples.showControlTypes = function () { var html = "<!DOCTYPE html ><html lang='en-US' ><head><title>Show Control Types</title>"; html += "<style type=\"text/css\">body { font-family:Calibri;}"; html += "table {border:1px solid gray; border-collapse:collapse;}"; html += "th {text-align:left; border:1px solid gray;}"; html += "td {border:1px solid gray;}</style>"; html += "</head><body>"; html += SDK.ControlSamples.getControlTypes(); html += "</body></html>"; var theWindow = window.open("", "_blank", "height=400,width=450,scrollbars=1,resizable=1", false); theWindow.document.open(); theWindow.document.write(html); theWindow.document.close(); }; SDK.ControlSamples.getControlTypes = function () { var html = "<table summary='This table displays information about each control on the form.'><thead><tr><th scope='col'>Control Label</th><th scope='col'>Attribute Type</th>" + "<th scope='col'>Attribute Format</th><th scope='col'>Control Type</th></tr></thead><tbody>"; var controls = Xrm.Page.ui.controls.get(); for (var i in controls) { var control = controls[i]; var label = control.getLabel(); if (label == null) { var attributeName; try { attributeName = control.getName(); if (attributeName != "undefined") { label = "attribute: " + attributeName; } } catch (e) { label = "Control is not bound to an attribute and does not have a label."; } } var attributeType; try { attributeType = control.getAttribute().getAttributeType(); } catch (e) { attributeType = "No Attribute"; } var attributeFormat; try { attributeFormat = control.getAttribute().getFormat(); } catch (e) { attributeFormat = "No Attribute"; } var controlType = control.getControlType(); html += "<tr><td>" + label + "</td><td>" + attributeType + "</td><td>" + attributeFormat + "</td><td>" + controlType + "</td></tr>"; } html += "</tbody></table>"; return html; };
getData
Returns the value of the data query string parameter passed to a Silverlight web resource.
controlObj.getData()
- Return Value
- Type: String This method is only available for Silverlight web resources. For web page (HTML) web resources, the data parameter can be extracted from the getSrc method.
getDefaultView
Returns the Id value of the default lookup dialog view.
controlObj.getDefaultView()
- Return Value
- Type: StringExample: See the SDK.ControlSamples.addCustomView function sample in addCustomView..
getDisabled
Returns whether the control is disabled. This method is not available for subgrid or web resource controls.
controlObj.getDisabled()
- Return Value
-
Type: BooleanExample:The SDK.ControlSamples.toggleEnableControls function sets a value that indicates whether the control is disabled based on the results of the getDisabled method.
SDK.ControlSamples.toggleEnableControls = function () { var controls = Xrm.Page.ui.controls.get(); for (var i in controls) { var control = controls[i]; if (control.getDisabled()) { control.setDisabled(false); } else { control.setDisabled(true); } } };
getLabel
Returns the label for the control
controlObj.getLabel()
- Return Value
-
Type:StringExample:The SDK.ControlSamples.toggleControlLabels function will show or hide a specified prefix for all control labels on the form.
SDK.ControlSamples.toggleControlLabels = function (prefix) { var controls = Xrm.Page.ui.controls.get(); for (var i in controls) { var control = controls[i]; var currentLabel = control.getLabel(); if (currentLabel.substring(0, prefix.length) == prefix) { var newLabel = currentLabel.substring(prefix.length); control.setLabel(newLabel); } else { control.setLabel(prefix + currentLabel); } } };
getName
Returns the name assigned to the control.
Note |
|---|
| The name assigned to a control is not determined until the form loads. Changes to the form may change the name assigned to a given control. |
controlObj.getName()
- Return Value
- Type: StringExample:See the SDK.ControlSamples.addCustomView function sample in addCustomView..
getParent
Returns a reference to the section object that contains the control.
controlObj.getParent()
- Return Value
-
Type: ObjectExample: The SDK.ControlSamples.showControlParents function will display a page in a new window showing the section label values for controls on the page.
SDK.ControlSamples.showControlParents = function () { var html = "<!DOCTYPE html ><html lang='en-US' ><head><title>Show Control Parents</title>"; html += "<style type=\"text/css\">body { font-family:Calibri;}"; html += "table {border:1px solid gray; border-collapse:collapse;}"; html += "th {text-align:left; border:1px solid gray;}"; html += "td {border:1px solid gray;}</style>"; html += "</head><body>"; html += SDK.ControlSamples.getControlParents(); html += "</body></html>"; var theWindow = window.open("", "_blank", "height=400,width=350,scrollbars=1,resizable=1", false); theWindow.document.open(); theWindow.document.write(html); theWindow.document.close(); }; SDK.ControlSamples.getControlParents = function () { var html = "<table summary='This table displays the parent section label for each control on the form.'><thead><tr><th scope='col'>Control Label</th><th scope='col'>Section Label</th></tr>" + "</thead><tbody>"; var controls = Xrm.Page.ui.controls.get(); for (var i in controls) { var control = controls[i]; var controlLabel = control.getLabel(); var sectionLabel = control.getParent().getLabel(); if (sectionLabel == null) { sectionLabel = "No Label"; } html += "<tr><td>" + controlLabel + "</td><td>" + sectionLabel + "</td></tr>"; } html += "</tbody></table>"; return html; };
getSrc
Returns the current URL being displayed in an IFrame or web resource.
IFrameControlObj.getSrc()
- Return Value
-
Type: StringExample: The SDK.ControlsSamples.showIframeUrls function displays the URL for every I-frame on the form
SDK.ControlSamples.showIframeUrls = function () { var controls = Xrm.Page.ui.controls.get(SDK.ControlSamples.isIframe); if (controls.length > 0) { var iframeUrls = []; for (var i in controls) { iframeUrls.push(controls[i].getSrc()); } var message = "The iframes on the current form have the following urls:\n\n- " + iframeUrls.join("\n- "); } else { var message = "There are no iframe controls on the current form."; } alert(message); }; SDK.ControlSamples.isIframe = function (control, index) { return control.getControlType() == "iframe"; };
getInitialUrl
Returns the default URL that an I-frame control is configured to display. This method is not available for web resources.
IFrameControlObj.getInitialUrl()
- Return Value
-
Type: StringExample: The SDK.ControlSamples.redirectAllIframes function sets the src for every I-frame on the form to www.microsoft.com, and then alerts the user with the old and new URL.
SDK.ControlSamples.redirectAllIframes = function () { var controls = Xrm.Page.ui.controls.get(SDK.ControlSamples.isIframe); if (controls.length > 0) { for (var i in controls) { var control = controls[i]; var controlName = control.getName(); var newUrl = "http://www.microsoft.com"; control.setSrc(newUrl); var oldUrl = control.getInitialUrl(); alert("The source of the iframe '" + controlName + "' has been changed from '" + oldUrl + "' to '" + newUrl + "'."); } } else { alert("There are no iframe controls on the current form."); } };
getObject
Returns the object in the form that represents an I-frame or web resource.
controlObj.getObject()
getVisible
Returns a value that indicates whether the control is currently visible.
Note |
|---|
| If the containing section or tab for this control is not visible, this method can still return true. To make certain that the control is actually visible, you need to also check the visibility of the containing elements. |
controlObj.getVisible()
- Return Value
-
Type: BooleanExample: The SDK.ControlSamples.toggleVisibleControls function hides or reveals all controls on the form each time the event occurs.
SDK.ControlSamples.toggleVisibleControls = function () { var controls = Xrm.Page.ui.controls.get(); for (var i in controls) { var control = controls[i]; if (control.getVisible()) { control.setVisible(false); } else { control.setVisible(true); } } };
refresh
Refreshes the data displayed in a Sub-Grid
controlObj.refresh()
Note |
|---|
| The refresh method is not available in the form OnLoad Event. |
Example:The SDK.ControlSamples.refreshAllSubGrids function refreshes every sub-grid on the form.
SDK.ControlSamples.refreshAllSubGrids = function () { var controls = Xrm.Page.ui.controls.get(SDK.ControlSamples.isSubGrid); if (controls.length > 0) { var subGridNames = ""; for (var i in controls) { controls[i].refresh(); subGridNames += (" - " + controls[i].getName() + "\n"); } alert("The following subgrids were refreshed: \n" + subGridNames); } else { alert("There are no subgrid controls on the current form."); } }; SDK.ControlSamples.isSubGrid = function (control, index) { return control.getControlType() == "subgrid"; };
removeOption
Removes an option from an Option Set control.
controlObj.removeOption(value)
- Arguments
- Number: The value of the option you want to remove.
Example:The SDK.ControlSamples.removeLastOption function removes the last option from the first optionset control on the form.
SDK.ControlSamples.removeLastOption = function () { var controls = Xrm.Page.ui.controls.get(SDK.ControlSamples.isOptionSet); if (controls.length > 0) { var firstOptionSet = controls[0]; var options = firstOptionSet.getAttribute().getOptions(); //The last option may be null when no default value is set. // Make sure the null option is not the one being removed. var lastOptionIndex = options.length - 1; var lastOption = null; if (options[lastOptionIndex].value != "null") { lastOption = options[lastOptionIndex]; } else { lastOption = options[lastOptionIndex - 1]; } if (lastOption.value != null) { firstOptionSet.removeOption(lastOption.value); alert("The option '" + lastOption.text + "' has been removed from the '" + firstOptionSet.getName() + "' control."); } else { alert("The '" + firstOptionSet.getName() + "' control does not have any options."); } } else { alert("There are no optionset controls on the current form."); } }; SDK.ControlSamples.isOptionSet = function (control, index) { return control.getControlType() == "optionset"; };
setData
Sets the value of the data query string parameter passed to a Silverlight web resource.
controlObj.setData()
- Arguments
- Type: String This method is only available for Silverlight web resources. For webpage (HTML) web resources the data parameter can be set by using the setSrc method.
setDefaultView
Sets the default view for the lookup control dialog.
controlObj.setDefaultView(viewGuid)
- Arguments
- Type: StringExample:See the SDK.ControlSamples.addCustomView function sample in addCustomView..
setDisabled
Sets whether the control is disabled. This method is not available for subgrid or web resource controls.
controlObj.setDisabled(bool)
- Arguments
- Boolean
Example:See the SDK.ControlSamples.toggleEnableControls function sample in getDisabled..
setFocus
Sets the focus on the control.
controlObj.setFocus()
Example:The SDK.ControlSamples.SetFocusDemo function will open a new page containing a table with rows for each enabled and visible control corresponding to an attribute. Each row contains a button that will use the window.opener to access the Xrm.Page object to call the setFocus method for the control in the entity record form.
SDK.ControlSamples.setFocusDemo = function () { var html = "<!DOCTYPE html ><html lang='en-US' ><head><title>Set focus demo</title>"; html += "<style type=\"text/css\">body { font-family:Calibri;}"; html += "table {border:1px solid gray; border-collapse:collapse;}"; html += "th {text-align:left; border:1px solid gray;}"; html += "td {border:1px solid gray;}</style>"; html += "<script type=\"text/javascript\" >"; html += "function setFocus(name) { "; html += "window.opener.Xrm.Page.data.entity.attributes.get(name).controls.get(0).setFocus();"; html += "}"; html += "</script>"; html += "</head><body>"; html += SDK.ControlSamples.buildFocusDemoTable(); html += "</body></html>"; var theWindow = window.open("", "_blank", "height=400,width=400,scrollbars=1,resizable=1", false); theWindow.document.open(); theWindow.document.write(html); theWindow.document.close(); }; SDK.ControlSamples.buildFocusDemoTable = function () { var html = "<table summary='This table displays a row for each enabled and visible control corresponding to an attribute. Each row has a button to call the setFocus method for that control on the page.'><thead><tr><th scope='col'>Control Label</th><th scope='col'>Set Focus</th>" + "</tr></thead><tbody>"; var attributes = Xrm.Page.data.entity.attributes.get(); for (var i in attributes) { var control = attributes[i].controls.get(0); //setFocus will cause an error if used on a control that is //disabled, not visible, or cannot accept focus. if (control != null && !control.getDisabled() && control.getVisible()) { var controlLabel = attributes[i].controls.get(0).getLabel(); var attributeName = attributes[i].getName(); html += "<tr><td>" + controlLabel + "</td><td><input type=\"button\" onclick=\"setFocus('" + attributeName + "');\" value='Set Focus on " + controlLabel + "' /></td></tr>"; } } html += "</tbody></table>"; return html; };
setLabel
Sets the label for the control.
controlObj.setLabel(label)
- Arguments
- String
Example: See the SDK.ControlSamples.toggleControlLabels function sample in getLabel..
setSrc
Sets the URL to be displayed in an IFrame or web resource.
IFrameControlObj.setSrc()
- Arguments
- StringExample: See the SDK.ControlSamples.redirectAllIframes function sample in getInitialUrl.
setVisible
Sets a value that indicates whether the control is visible.
controlObj.setVisible()
- Arguments
- Boolean
Example: See the SDK.ControlSamples.toggleVisibleControls function sample in getVisible.
Note |
|---|
| When you selectively show fields to users in code that runs in the Onload event, we recommend that you configure the fields to not be visible by default and then use setVisible(true) to show the fields when conditions are right. Using setVisible(false) to hide fields in the Onload event may result in the field briefly appearing to the user before being hidden. If you are hiding a larger number of fields using setVisible(false), consider if you can group them together into tabs or sections and hide the tab or section rather than the fields separately. This will provide better performance. |
Microsoft Dynamics CRM 2011
Send comments about this topic to Microsoft.
© 2013 Microsoft Corporation. All rights reserved.