Поделиться через


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

 

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.

Xrm.Page.data.entity Properties and Methods

  • 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.

attributes

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.

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.

Note

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

getEntityName

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"
    

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

OnSave

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

addOnSave

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);
    }
    

removeOnSave

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);
    }
    

getPrimaryAttributeValue

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.

save

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.

See Also

Client-side programming reference
Form scripting quick reference
Xrm.Page.data.entity attribute (client-side reference)
Write code for Microsoft Dynamics 365 forms
Use the Xrm.Page object model

Microsoft Dynamics 365

© 2016 Microsoft. All rights reserved. Copyright