Announcements
No record found.
I am using web api to retrieve records from multiple entities(which are added to a dynamic list).i need the name of the entity in web api response to address business requirement. i see the request URL in @odata.context property.Is there any way we can get the schemaname\displayname of the entity in web api response?
Hi,
I used this to get first the entitymetadataid by entityname: "/api/data/v8.2/EntityDefinitions?$filter=LogicalName%20eq%20'" + entityName + "'&$select=MetadataId"
With these EntityMetadataID you can get all Metadata from the entity like this: "/api/data/v8.1/EntityDefinitions(" + entityMetadataID + ")?$expand=Attributes"
Take a look in my question here: https://community.dynamics.com/crm/f/microsoft-dynamics-crm-forum/370899/retrieve-attributes-from-record-without-entitymetadataid
Hi Gowtham,
I thought you should create another function to retrieve entity's metadata with your current entity name variable by EntityDefinitions(LogicalName='xxx'),
then get its display name from callback result.
var Name = Xrm.Page.data.entity.getEntityName(); var record = retrieveEntityMetadata(Name); console.log(record["DisplayName"]["UserLocalizedLabel"].Label); function retrieveEntityMetadata(entityName) { var data = null; var req = new XMLHttpRequest(); req.open('GET', Xrm.Page.context.getClientUrl() "/api/data/v9.0/EntityDefinitions(LogicalName='" entityName "')", false); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.setRequestHeader("Prefer", "odata.include-annotations=*"); req.send(); if (req.readyState == 4 /* complete */ ) { if (req.status == 200) { data = JSON.parse(req.response); } else { var error = JSON.parse(req.response).error; console.log(error.message); } } return data; }
Result:
Syntax:
https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/webapi/retrieve-metadata-name-metadataid#retrieve-metadata-items-by-name
Attributes in entity's metadata:
https://docs.microsoft.com/en-us/dynamics365/customer-engagement/web-api/entitymetadata?view=dynamics-ce-odata-9
Regards,
Clofly
Thanks Daniel!!
However, I am not looking at retrieving entitydefinitions.
The requirement is when i retrieve account records,from response ,how do i know that the records retrieved are of entity "Account"(and not contact)?
To elaborate, we have a drop down which lists all the entities(retrieved from metadata using entitydefinitions) and once we select a particular entity, we need to retrieve records for that entity based on some conditions. My question is , once we retrieved records of entity 'x', How to i know from response that the records are of type entity 'x'?
I thought "@odata.context" property would be actually what you want, as you mentioned it in your question.
You could search for the property description, it's context URL for entity.
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
Congratulations to our 2026 Super Stars!
We are thrilled to have these Champions in our Community!
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Muhammad Shahzad Sh... 71 Most Valuable Professional
Abhilash Warrier 66 Super User 2026 Season 1
ManoVerse 51 Super User 2026 Season 1