JavaScript – CRM.Page.data.entity

In this post I want to quickly review some of the commonly used methods of XRM.Page.data.entity in terms of Dynamics 365 JavaScript.

I won’t document all of the capabilities here, just some of the methods I commonly use. If you need a full reference guide, please consult;

https://msdn.microsoft.com/en-us/library/gg334720.aspx#Xrm.Page.data.entity Properties and Methods

getEntityName

Useful if you need the entity name for the current record.

Var entityName = Xrm.Page.data.entity.getEntityName();

getId

Useful if you want to know the GUID for the current record

Xrm.Page.data.entity.getId();

getIsDirty

Useful if you want to know if any unsaved changes exist.

var isDirty = Xrm.Page.data.entity.getIsDirty();

This will return true is false is the page is dirty or not.

getPrimaryNameAttribute

Useful if you want to return then primary name of the current entity. (So on contact it would show fullname, on account name etc etc.)

var name = Xrm.Page.data.entity.getPrimaryAttributeValue();

save

Saves the current record!

Xrm.Page.data.entity.save(); // ** Just saves current record
Xrm.Page.data.entity.save("saveandclose") // ** Does a save and close
Xrm.Page.data.entity.save("saveandnew") // ** Save and new

These are all simple code snippets that are often used in JavaScript in Dynamics 365 forms. J

One thought on “JavaScript – CRM.Page.data.entity

  1. Pingback: JavaScript – My Collection | Microsoft Dynamics CRM and Unified Service Desk

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s