The views and opinions expressed in this blog are those solely of the author(s) and do not necessarily reflect Microsoft’s current policy, position, or branding. For official announcements and guidance on Dynamics 365 apps and services, please visit the Microsoft Dynamics 365 Blog.
Personalized Community is here!
Quickly customize your community to find the content you seek.
Choose your path Increase your proficiency with the Dynamics 365 applications that you already use and learn more about the apps that interest you. Up your game with a learning path tailored to today's Dynamics 365 masterminds and designed to prepare you for industry-recognized Microsoft certifications.
Visit Microsoft Learn
2020 Release Wave 2Discover the latest updates and new features to Dynamics 365 planned through March 2021.
Release overview guides and videos Release Plan | Preview 2020 Release Wave 2 TimelineWatch the 2020 Release Wave 1 virtual launch event
Ace your Dynamics 365 deployment with packaged services delivered by expert consultants. | Explore service offerings
Connect with the ISV success team on the latest roadmap, developer tool for AppSource certification, and ISV community engagements | ISV self-service portal
The FastTrack program is designed to help you accelerate your Dynamics 365 deployment with confidence.
FastTrack Program | Finance TechTalks | Customer Engagement TechTalks | Upcoming TechTalks
The humble Entity is one of core building blocks of CRM and CRM development.
When CRM developers look at things they should see things in entities like the matrix picture.
When a customer tells you the requirements you should be thinking about it in entities
You are an entity called CRM Developer!
Entities do a lot in CRM, to understand what they are and what they do I think it helps to view them in different ways
Entities are used to model the business data of the customer to accompany the out of the box entities which exist in the default CRM system (account, task, contact, business unit)
Most entities have at least one form in CRM.
Customizations are organised (to some extent around entities) in your solutions
Plugins are triggered by actions on Entities (you can add multiple triggers on a plugin). The messages (read actions on an entity) aer
Entities have a status and status reason. These values can be used to drive the entity through a process/life cycle. To learn more about Status and Status reason read the blogs below
CRM 2013 – Understanding Status and Status Reason – think before deleting them
CRM 2015 – how to find Statecode value
Security roles set access rights on entities – Create, Read, Write, Delete, Append, Append To, Assign, Share.
Entities can be owned by users/teams and these provide access levels such as none, user, business unit, child business unit, organisational.
When learning about topics in CRM it’s good policy to start with the CRM SDK and find the truth about entities, find out what properties and methods entities have. When I use the term CRM SDK I mean the CRM SDK documentation
Development for Microsoft Dynamics CRM Online and on-premises (CRM SDK)
You could also look at the CRM Developer Website, which I wrote a blog about recently
CRM Developer Centre gets updated and it looks good
What properties/members do you get with the Entity
The Entity has a number of properties but here are the keys ones
The attributes parameter holds a collection of all the fields in an Entity. The atrributes collection works by holding fields which have a value. If a field is null it isn’t included in the attributes collection (when you call from plugins).
You often need to check for a value in the Attributes collection using the contains method
This will create lots of if statements with contains, if true retrieve the attribute type code. You can work around this by using Entity.GetAttributeValue which will get the value if the field exists in the Attributes collection or return the default value for simple variables or null for complex variables. Read more about it using the link below
CRM 2013 – using Entity.GetAttributeValue instead of Entity.Contains
Each Entity has it’s own individual name stored as a string. The logical name is useful because sometimes in the code you will need to know what type of entity it is e.g.
task, account, phonecall, contact.
The LogicalName can be useful if you have plugin code which is triggered on a number of different entities.
The all important Id of the entity record. This holds the Guid. This is important because when you retrieve any information you can use this ID to retrieve the individual Entity record and ask for particular fields of interest.
Gets the state of the entity, useful
Good practise for CRM developers is to use Early binding which will create an Entities file and allow you to create Account, Contact, Task records.
Early binding strongly types the field values for an entity. These values are the same fields you would find in the attributes collection on the Entity object.
The easy way to make your Entities file is to use the CRM Early bound generator
CRM 2013 Tool – CRM Early Bound Generator
Whilst you are there don’t forget to make your optionset enums
CRM 2013 – Create Enumerations for option sets
When you are using early bound classes in your CRM code you are then extending Entity object with the new early bound classes
Entity –> Account, Contact, Task, etc
Using Entity can be useful when creating common functions because all your early bound classes inherit from Entity.
The code below checks the entity (which is an Entity object) to check the name. The code in the example could be either a Task or PhoneCall. The Complete activity either sets a task to completed or a phonecall to made.
else if (entity.LogicalName.Equals(PhoneCall.EntityLogicalName))
It’s useful to remember all early bound entities inherit from Entity.
The EntityReference object in CRM is a lookup to an Entity object. An EntityReference has LogicalName and Id (guid) of the entity.
When ever you see a lookup in a CRM form you know this is an EntityReference with just enough detail for you to retrieve the Entity object.
There is a good code tip is you can get an Entity Reference from an Entity object
Hosk CRM Dev Tip – Get EntityReference from Entity
EntityReference entRef = entity.ToEntityReference();
When creating new lookups on your forms, it’s best practise to put ID on the end of the field name, so CRM developers can easily find the lookups
Hosk CRM Dev Tip – add ID suffix to lookup fields
Business Applications communities