Microsoft Dynamics CRM 2011 JavaScript Development Reference

Standard

I’ve been working on the development of a CRM 2011 deployment for a few months now and I’ve found myself poking around the web to all kinds of different websites looking for references to different parts of the SDK for JavaScript.

Now that I’ve become more familiar with the MSDN Library I’ve decided to compile all the major functions for the JavaScript reference into one easy reference point with links branching out to the MSDN library. The MSDN library is amazing but can be rough to navigate and find what you really want fast.

Hope others find this cheat sheet useful.

If you have anything to add, feel free to leave a comment.

Xrm.Page.context Methods

getAuthenticationHeader A deprecated method that returns the encoded SOAP header necessary to use Microsoft Dynamics CRM Web service calls using JScript.
getCurrentTheme Returns a string representing the current Microsoft Office Outlook theme chosen by the user.
getOrgLcid Returns the LCID value that represents the Microsoft Dynamics CRM Language Pack that is the base language for the organization.
getOrgUniqueName Returns the unique text value of the organizations name.
getQueryStringParameters Returns an array of key value pairs representing the query string arguments that were passed to the page.
getServerUrl Returns the base server URL. When a user is working offline with Microsoft Dynamics CRM for Microsoft Office Outlook, the URL is to the local Microsoft Dynamics CRM Web services.
getUserId Returns the GUID value of the SystemUser.id value for the current user.
getUserLcid Returns the LCID value that represents the Microsoft Dynamics CRM Language Pack that is the user selected as their preferred language.
getUserRoles Returns an array of strings representing the GUID values of each of the security roles that the user is associated with.
isOutlookClient Returns a Boolean value indicating if the user is using Microsoft Dynamics CRM for Microsoft Office Outlook.
isOutlookOnline Returns a Boolean value indicating whether the user is connected to the Microsoft Dynamics CRM server while using Microsoft Dynamics CRM for Microsoft Office Outlook with Offline Access. When this function returns false, the user is working offline without a connection to the server. They are interacting with an instance of Microsoft Dynamics CRM running on their local computer.
prependOrgName Prepends the organization name to the specified path.

 

Xrm.Page.data.entity Attribute Methods

Method Attribute Types Description
addOnChange All Sets a function to be called when the attribute value is changed.See also removeOnChange
fireOnChange All Causes the OnChange event to occur on the attribute so that any script associated to that event can execute.
getAttributeType All Returns a string value that represents the type of attribute.
getformat All Returns a string value that represents formatting options for the attribute.
getInitialValue boolean, optionset Returns the initial value for Boolean or optionset attributes.
getIsDirty All Returns a Boolean value indicating if there are unsaved changes to the attribute value.
getMax money, decimal, integer, double Returns a number indicating the maximum allowed value for an attribute.
getMaxLength string, memo Returns a number indicating the maximum length of a string or memo attribute.
getMin money, decimal, integer, double Returns a number indicating the minimum allowed value for an attribute.
getName All Returns a string representing the logical name of the attribute.
getOption optionset Returns an option object with the name matching the argument passed to the method.
getOptions optionset Returns an array of option objects representing the valid options for an optionset attribute.
getParent All Returns the entity object that is the parent to the attribute.
getPrecision money, decimal, integer, double Returns the number of digits allowed to the right of the decimal point.
getRequiredLevel All Returns a string value indicating whether a value for the attribute is required or recommended. See also setRequiredLevel
getSelectedOption optionset Returns the option object that is selected in an optionset attribute.
getSubmitMode All Returns a string indicating when data from the attribute will be submitted when the record is saved. See also setSubmitMode
getText optionset Returns a string value of the text for the currently selected option for an optionset attribute.
getUserPrivilege All Returns an array of privileges that contain Boolean values indicating if the user can create, read or update data values for an attribute.
getValue All Retrieves the data value for an attribute. See also setValue.
removeOnChange All Removes a function from the OnChange event hander for an attribute. See also addOnChange
setRequiredLevel All Sets whether data is required or recommended for the attribute before the record can be saved. See also getRequiredLevel.
setSubmitMode All Sets whether data from the attribute will be submitted when the record is saved. See also getSubmitMode.
setValue All Sets the data value for an attribute. See also getValue.

 

Xrm.Page.data.entity Methods

Method Description
addOnSave Sets a function to be called when the record is saved.
getDataXml Returns a string representing the xml that will be sent to the server when the record is saved.
getEntityName Returns a string representing the logical name of the entity for the record.
getId Returns a string representing the GUID id value for the record.
getIsDirty Returns a Boolean value that indicates if any fields in the form have been modified.
removeOnSave Removes a function from the OnSave event hander.
save Saves the record. This method has three possible parameters.

 

Form Event Handler Execution Context Reference

getContext Returns the Xrm.Page.context object.
getDepth Returns a value that indicates the order in which this handler is executed.
getEventArgs Returns an object with methods to manage the Save event.
getEventSource Returns a reference to the object that the event occurred on.
getSharedVariable Retrieves a variable set using setSharedVariable.
setSharedVariable Sets the value of a variable to be used by a handler after the current handler completes.

 

Xrm.Page.ui Methods

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.

 

Xrm.Page.ui Control Methods

Method Control Types Description
addCustomView Lookup Adds a new view for the lookup dialog.
addOption Option Set Adds an option to an Option set control.
clearOptions Option Set Clears all options from an Option Set control.
getAttribute Standard, Lookup, OptionSet Returns the attribute that the control is bound to.
getControlType All Returns a value that categorizes controls.
getData Silverlight Web resources. Returns the value of the data query string parameter passed to a Silverlight Web resource. For more information, see setData.
getDefaultView Lookup Returns the ID value of the default lookup dialog view. For more information, see setDefaultView.
getDisabled All except SubGrid. Returns a value that indicates whether the control is disabled. For more information, see setDisabled.
getLabel All Returns the label for the control. See also setLabel
getName All Returns the name assigned to the control.
getParent All Returns a reference to the section object that contains the control.
getSrc IFrame, Web Resource Returns the current URL being displayed in an IFRAME. See also setSrc
getInitialUrl IFrame Returns the default URL that an IFrame control is configured to display.
getObject IFrame, Web resource Returns the object in the form representing an IFrame or Web resource.
getVisible All Returns a value that indicates whether the control is currently visible. For more information, see setVisible.
refresh SubGrid Refreshes the data displayed in a Sub-Grid
removeOption Option Sets Removes an option from an Option Set control.
setData Silverlight Web resources. Sets the value of the data query string parameter passed to a Silverlight Web resource. For more information, see getData.
setDefaultView Lookup Sets the default view for the lookup control dialog. For more information, see getDefaultView.
setDisabled All except Web Resources and SubGrid. Sets a value that indicates whether the control is disabled. See also getDisabled
setFocus All Sets the focus on the control.
setLabel All Sets the label for the control. For more information, see getLabel.
setSrc IFrame and Web Resource Sets the URL to be displayed in an IFrame. See also getSrc
setVisible All Sets a value that indicates whether the control is visible. For more information, see getVisible.

 

Xrm.Page.ui.controls Collection Methods

forEach Applies the action contained within a delegate function
get Returns one or more controls depending on the arguments passed.
Argument Return Value Type
None All the controls Array
String The control that matches the name Object
getLength Returns the number of controls in the collection

 

Xrm.Page.ui.navigation.items Collection Methods

forEach Applies the action contained within a delegate function.
get Returns one or more navigation items depending on the arguments passed.
Argument Return Value Type
None All the navigation items Array
String The item that matches the name Object
Number The item that matches the index Object
Delegate function (attribute, index) Any navigation items causing the delegate function to return true Array
getLength Returns the number of navigation items in the collection.

 

Xrm.Page.ui.formSelector.items Collection Methods

forEach Applies the action contained within a delegate function.
get Returns one or more roleForms.
Argument Return Value Type
None All the items Array
String The item that matches the name Object
Number The item that matches the index Object
Delegate function (attribute, index) Any items that cause the delegate function to return true Array
getLength Returns the number of roleForms in the collection.

 

Xrm.Page.ui.formSelector members

Member Type Description
items Collection A Collection of all the form items accessible to the current user.
getCurrentItem Method Returns a reference to the form currently being shown.

 

Xrm.Page.ui.tabs Collection

forEach Applies the action contained within a delegate function.
get Returns one or more tabs.
Argument Return Value Type
None All the tabs Array
String The tab that matches the name Object
Number The tab that matches the index Object
Delegate function (attribute, index) Any tabs that cause the delegate function to return true Array
getLength Returns the number of tabs in the collection.

 

Xrm.Page.data.entity.attributes Collection Methods

forEach Applies the action contained within a delegate function.
get Returns one or more attributes.
Argument Return Value Type
None All the attributes Array
String The attribute that matches the name Object
Number The attribute that matches the index Object
Delegate function (attribute, index) Any attributes that cause the delegate function to return true Array
getLength Returns the number of items in the collection.

 

Advertisement