web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

entity name in web api response

(0) ShareShare
ReportReport
Posted on by 2

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?

I have the same question (0)
  • Suggested answer
    Daniel Schneider Profile Picture
    172 on at

    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

  • cloflyMao Profile Picture
    25,210 on at

    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:

    pastedimage1574154317964v1.png

    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

  • Goutham A Profile Picture
    2 on at

    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'?

  • cloflyMao Profile Picture
    25,210 on at

    Hi Gowtham,

    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.

    pastedimage1574217195882v1.png

    Regards,

    Clofly

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.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 71 Most Valuable Professional

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 66 Super User 2026 Season 1

#3
ManoVerse Profile Picture

ManoVerse 51 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans