One of the strangest part of the Dynamics CRM WebApi is the pluralisation of the entity names.
In the old OData endpoint, the entity set name was <EntityLogicalName>Set – however in the OData 4.0 endpoing, the Logical Name is pluralised by using a simplistic set of rules which often results in the incorrect plural name being picked.
This introduced a conundrum – Performance vs. correctness. Do we query the metadata for the Entity Set name at runtime – or use a duplicate set of over simplified rules in our JavaScript?
The good news is that with version 9, the Xrm Api now supports:
Xrm.Utility.getEntitySetName("contact")
This will return “contacts” and so we can safely use this without worrying if the plural name is correct or not or indeed if it changes in the future.
UPDATE: As it turns out – this method isn’t actually documented and so we have to use the getEntityMetadata function to be fully supported – see https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/reference/xrm-utility/getentitymetadata
You can use it as follows:
Xrm.Utility.getEntityMetadata("lead",["EntitySetName"]) .then(function(m){ console.log(m.EntitySetName); })
Hope this helps!
Original Post https://develop1.net/public/post/2017/10/16/Counting-Sheeps