Xrm.Page.data.entity (client-side reference)

 

Updated: November 29, 2016

Applies To: Dynamics 365 (online), Dynamics 365 (on-premises), Dynamics CRM 2016, Dynamics CRM Online

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.

attributes

The collection of attributes for the entity.

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.

OnSave

Use the addOnSave and removeOnSave methods to add or remove event handlers to the save event

getPrimaryAttributeValue

Gets a string for the value of the primary attribute of the entity.

save

Saves the record with the options to close the form or open a new form after the save is completed.

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 Collections (client-side reference). See Xrm.Page.data.entity attribute (client-side reference) for properties and methods available to objects in this collection.

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.

System_CAPS_noteNote

This function does not work with Microsoft Dynamics 365 for tablets.

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>"

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

Xrm.Page.data.entity.getEntityName()
Return Value

Type: String. The name of the entity.

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

"account"

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}"

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

Xrm.Page.data.entity.getIsDirty()
Return Value

Type: Boolean

Use the addOnSave and removeOnSave methods to add or remove event handlers to the save event

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

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

Type: function reference

Remarks: The function will be added to the bottom of the event handler pipeline. The execution context is automatically set to be passed as the first parameter passed to event handlers set using this method. See Execution context (client-side reference) for more information.

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

function displayOrgName(execContext)
{
    try {
        alert(execContext.getContext().getOrgUniqueName());
    }
    catch (e) {
        alert(e.message);
    }
}

function addMessageToOnSave() {
    Xrm.Page.data.entity.addOnSave(displayOrgName);
}

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

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

Type: function reference

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

function displayOrgName(execContext)
{
    try {
        alert(execContext.getContext().getOrgUniqueName());
    }
    catch (e) {
        alert(e.message);
    }
}

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

Gets a string for the value of the primary attribute of the entity.

Xrm.Page.data.entity.getPrimaryAttributeValue()

Each entity has one string attribute that is designated as the PrimaryNameAttribute. The value for this attribute is used when links to the record are displayed.

Return Value

Type: String. The value of the primary attribute of the entity.

Remarks

This method is only available for Updated entities.

Saves the record synchronously with the options to close the form or open a new form after the save is completed.

Both Xrm.Page.data.save and Xrm.Page.data.entity.save will save the record, but Xrm.Page.data.save provides callback functions after the save operation completes.

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 using the Save command.

save("saveandclose")

This is the equivalent of using the Save and Close command.

save("saveandnew")

This is the equivalent of the using the Save and New command.

Remarks

When using quick create forms in the web application the saveandnew option is not applied. It will always work as if saveandclose were used. Quick create forms in Microsoft Dynamics 365 for tablets will apply the saveandnew behavior.

Microsoft Dynamics 365

© 2016 Microsoft. All rights reserved. Copyright

Community Additions

ADD
Show: