Xrm.Page.data.entity

[Applies to: Microsoft Dynamics CRM 2011]

Xrm.Page.data.entity provides methods to retrieve information specific to the record displayed on the page, the save method, and a collection of all the attributes included in the form. Attribute data is limited to attributes represented by fields on the form.

The following table lists the methods of Xrm.Page.data.entity.

 

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.

addOnSave

Sets a function to be called when the record is saved.

Xrm.Page.data.entity.addOnSave([function reference])
Parameter
Type: function pointer

Remarks: The function will be added to the bottom of the event handler pipeline.

Example:In this example, the JScript library contains two functions. Adding the addMessageToOnSave function to the form OnLoad event will add the displayMessage function as a handler for the OnSave event.

function addMessageToOnSave() {
 Xrm.Page.data.entity.addOnSave(displayMessage);
}
function displayMessage() {
 alert("message");
}

getDataXml

Returns a string representing the XML that will be sent to the server when the record is saved. Only data in fields that have changed are set to the server.

Xrm.Page.data.entity.getDataXml()
Return Value
Type: String

Example:In this example, the following three fields for an account record were updated:

  • name

  • accountnumber

  • telephone2

"<account>
<name>Contoso</name>
<accountnumber>55555</accountnumber>
<telephone2>425 555-1234</telephone2>
</account>"

getEntityName

Returns a string representing the logical name of the entity for the record.

Xrm.Page.data.entity.getEntityName()
Return Value
Type: String

Example:In this example, an account record was being edited.

"account"

getId

Returns a string representing the GUID id value for the record.

Xrm.Page.data.entity.getId()
Return Value
Type: String

Example:The GUID Id value for the record.

"{825CB223-A651-DF11-AA8B-00155DBA3804}"

getIsDirty

Returns a Boolean value that indicates if any fields in the form have been modified.

Xrm.Page.data.entity.getIsDirty()
Return Value
Type: Boolean

removeOnSave

Removes a function from the OnSave event hander.

Xrm.Page.data.entity.removeOnSave([function reference])
Parameter
Type: function reference

Example:In this example, the JScript library contains two functions. Adding the removeMessageFromOnSave function to a form event will remove the displayMessage function as a handler for the OnSave event.

function removeMessageFromOnSave() {
 Xrm.Page.data.entity.removeOnSave(displayMessage);
}

function displayMessage() {
 alert("message");
}

save

Saves the record.

Xrm.Page.data.entity.save( null | "saveandclose" |"saveandnew" )
Arguments
save()
If no parameter is included the record will simply be saved. This is the equivalent of the user clicking the Save button in the ribbon.

save("saveandclose")
This is the equivalent of the user clicking the Save and Close button in the ribbon.

save("saveandnew")
This is the equivalent of the user clicking the Save and New button in the ribbon.

The Xrm.Page.data.entity.attributes collection provides methods to access the data for a record displayed on the form. For more information about this collection, see Xrm.Page.data.entity Attribute Methods.

Microsoft Dynamics CRM 2011
Send comments about this topic to Microsoft.
© 2013 Microsoft Corporation. All rights reserved.

Community Additions

ADD
Show: