Skip to content
Microsoft Dynamics 365 CRM Tips and Tricks
By Inogic
  • Blogs
  • D365 Apps
  • Inogic
  • D365 / Power Platform Services
  • Maplytics Docs
  • D365 Apps Docs
    • Omnichannel Apps
      • WhatsApp4Dynamics
      • TextSMS4Dynamics
      • LiveChat4Dynamics
    • File and Storage Managment
      • Attach2Dynamics
      • SharePoint Security Sync
    • Visualization Apps
      • Map My Relationships
      • Kanban Board
      • Business Process Checklist
    • Productivity Apps
      • Click2Clone
      • Click2Export
      • Undo2Restore
      • Lead Assignment and Distribution Automation
      • Alerts4Dynamics
      • Translate4Dynamics
      • Subscription Recurring Billing Management
    • User Adoption Apps
      • DeDupeD
      • User Adoption Monitor
      • Gamifics365
    • Integration Apps
      • Marketing4Dynamics
      • InoLink

Retrieve Metadata using Name in Web API

By Inogic | February 28, 2017
0 Comment

Dynamics 365 introduced a lot of new features and improvements over the previous versions to offer more control and functionalities to the user. The ability to retrieve metadata using name is one such improvement in Web API.

Previously, to retrieve entity metadata, users needed to use ‘metadataid’. With the addition of this improvement, users can now retrieve the Entity/Attributes/Global Option Set meta by using the logical name.

When do we need to retrieve metadata?

There are many scenarios where the user needs object type code, primary attributes, localized label, list of entity attributes, etc. or when the user wants option set metadata. In such situations the user needs to read the entity metadata which can now be easily retrieved.

Let us see an example to understand how to retrieve Entity metadata:

  • To retrieve Contact entity metadata using Name, use the script mentioned below;
//this function is used to retrieve entityMetadata
function retrieveEntityMetaData() {

    var entityName = "";
    try {       
        //set variable value
        entityName = "contact";

        //create AJAX request
        $.ajax({
            type: "GET",
            contentType: "application/json; charset=utf-8",
            datatype: "json",
            url: encodeURI(this.getWebAPIPath() + "EntityDefinitions(LogicalName='" + entityName + "')"),

            beforeSend: function (xhr) {
                //Specifying this header ensures that the results will be returned as JSON.             
                xhr.setRequestHeader("Accept", "application/json");
                xhr.setRequestHeader("Accept", "application/json");
                xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8");
                xhr.setRequestHeader("OData-MaxVersion", "4.0");
                xhr.setRequestHeader("OData-Version", "4.0");
            },
            success: function (data, textStatus, xhr) {
                //Call successCallback
                retrieveEntityMetaDataSuccess(data);
            },
            error: function (xhr, textStatus, errorThrown) {
                errorCallback(xhr);
            }
        });

    } catch (e) {
        showMessage(e.message);
    }
}
  •  The ‘success callback’ function mentioned below will get the metadata;
//success call back
function retrieveEntityMetaDataSuccess(data) {
    try {

        if(data != null) {

            //get objectTypeCode
            var objectTypeCode = data.ObjectTypeCode;

            //get primary name
            var primaryAttribute = data.PrimaryNameAttribute;
        }
    }
    catch(e) {
        showMessage(e.message);
    }
}
  •  If you want to retrieve metadata of any particular attribute then pass the following in url parameter in Ajax request;
  url:encodeURI(this.getWebAPIPath() + "EntityDefinitions(LogicalName='" + entityName + "')/Attributes(LogicalName='parentcustomerid')") ,
success: function (data, textStatus, xhr) {
                        //Call successCallback
                        successCallback(data);
                    },

 In successCallback function, use data.value to get the attribute metadata.

  • If you want to retrieve all the entity attributes then pass the following in url parameter in Ajax request;
url:encodeURI(this.getWebAPIPath() + "EntityDefinitions(LogicalName='" + entityName + "')/Attributes")

 In successCallback function, use data.value to get the list of entity attributes.

  • If you want to retrieve relationship metadata then you can use the following in url parameter in Ajax request;
url: encodeURI(this.getWebAPIPath() + "RelationshipDefinitions(SchemaName='account_primary_contact')")

 In successCallback function, use data.value to get the relationship metadata.

  • If you want to retrieve Global option set metadata then use the following in url parameter in Ajax request;
url: encodeURI(this.getWebAPIPath() + "GlobalOptionSetDefinitions(Name='budgetstatus')")

In successCallback function, use data.Options to get all options.

 

Conclusion:

Now with the addition of the ability to retrieve metadata using name in Dynamics 365, users can easily retrieve metadata.

One Pic = 1000 words! Analyze data 90% faster with visualization apps!

Get optimum visualization of Dynamics 365 CRM data with –
Kanban Board – Visualize Dynamics 365 CRM data in Kanban view by categorizing entity records in lanes and rows as per their status, priority, etc.
Map My Relationships – Map My Relationships – Visualize connections and relationships between Dynamics 365 CRM entities or related records in a Mind Map view.

Category: Dynamics 365 JavaScript WEB API Tags: Dynamics 365 Web API, Retrieve Metadata using Name, Retrieve Metadata using Name in Web API, Web API
Post navigation
← Watch out for Issues with Version & Updating Plug-in assembly in Dynamics 365/CRM Detect Duplicates Ribbon Button in Dynamics 365 →

Follow Us!

Follow Us on FacebookFollow Us on TwitterFollow Us on LinkedInFollow Us on YouTubeFollow Us on InstagramFollow Us on E-mailFollow Us on Docs

Blog Series

  • Power Apps – Model Driven Apps
  • Power Apps – Canvas App
  • Power Pages
  • Power Automate
  • Power BI
  • AI Builder
  • Copilot
  • Azure OpenAI
  • Microsoft Teams
  • Dynamics 365 for Field Service

Recent Innovations

Top Reasons your Dynamics 365 CRM Needs a Translation App today!

Guide to Branding Your Dynamics 365 Live Chat Integration App!

AI Meets WhatsApp in Dynamics 365

How to Track Mailchimp Customer Journey Email Insights in Dynamics 365 CRM?

Never Miss an Important CRM Alert Again: Introducing Snooze in Dynamics 365 Notifications

Top Questions About Dynamics 365 CRM Document & Storage Management—Answered!

Summer 2025 Dynamics 365 Maps Release: Smarter Routing, Azure Maps, Canvas Apps & More!

Detect and Merge Dynamics 365 CRM Duplicate Records with New DeDupeD Features!

Recent Posts

  • Dynamics 365 CRM Field Merge: A Smarter Way to Manage Duplicate Data!
  • How to Configure Generative AI Plugin in Copilot for Improved Customer Service
  • Connecting ESRI ArcGIS system to Dynamics 365 CRM with Maplytics!
  • Retrieving Masked Field Values Programmatically in Dynamics 365
  • Microsoft 365 Copilot Services Outsourcing: Smartest Move for Business Growth!

Archives

SiteLock
Copyright © 2025 Inogic. All Rights Reserved
Iconic One Theme | Powered by Wordpress