Microsoft Dynamics 365 CRM Tips and Tricks
By Inogic
Skip to content
  • Blogs
  • D365 Apps
  • Inogic
  • D365 / Power Platform Services
  • Maplytics Docs
  • New D365 Apps Docs
    • Subscription Recurring Billing Management
    • Marketing4Dynamics
    • Gamifics365
    • Business Process Checklist
  • D365 Apps Docs
    • Alerts4Dynamics
    • Attach2Dynamics
    • SharePoint Security Sync
    • Kanban Board
    • Lead Assignment and Distribution Automation
    • Map My Relationships
    • User Adoption Monitor
    • InoLink
    • Click2Clone
    • Click2Export
    • Undo2Restore
    • Auto Tax Calculator

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 Apps Portal
  • Power Automate
  • Power BI
  • AI Builder
  • Dynamics 365 for Field Service
  • Dynamics 365 for Project Service Automation
  • Dynamics 365 for Mobiles and Tablets

Recent Updates

New Release: Business Process Checklist app for streamlining business processes in Microsoft Dynamics 365 CRM

Document Management Solution for your Dynamics 365 CRM – How to choose the better one?

Integrate Dynamics 365 Customer Engagement with SharePoint – The secure way!

Get valuable insights into CRM data with new-age smart Data Visualization apps – Kanban Board and Map My Relationships!

Visualize intricate details in Dynamics 365 CRM with finesse using latest Map My Relationships feature

Top 5 Reasons why Subscription and Recurring Billing Management is must for easy subscription management within Dynamics 365 CRM!

QuickBooks Online + Dynamics 365 CRM – Get Accounting & Sales Data on one platform with InoLink!

From beginners to experts – Shorten the journey of adapting to Dynamics 365 CRM with our advanced User Adoption Monitor app!

New Age Automation App to Clone/Copy Records in Dynamics 365 CRM with just 1 Click

1 Click is all you need to Undo, Restore / Retrieve Deleted Data within Dynamics 365 CRM!

Bid goodbye to export woes with Dynamics 365 CRM 1 Click productivity app – Click2Export

Alerts4Dynamics – New age Dynamics 365 CRM alert management solution to bridge the information gap!

Automatically set user availability while assigning leads in Dynamics 365 CRM – New Feature of our Lead Assignment and Distribution Automation!

Mailchimp integration with Dynamics 365 CRM – Sync Audience, Tags, Campaigns and more!

Gamification in Microsoft Dynamics 365 CRM – Set goals, Make them fun, and Everyone wins!

Recent Posts

  • Outsourcing Dynamics 365 and Power Platform Development – Choose Inogic for Experience, Expertise, and More!
  • Microsoft Release 2023 Wave 1: Form creation and management in Real-Time Marketing – Part 2
  • Configure the Right Subscription-Based Pricing Model for Your Product within Microsoft Dynamics 365 CRM!
  • Microsoft Release 2023 Wave 1: Form creation and management in Real-Time Marketing – Part 1
  • Webinar: The Magic of Gamification in Microsoft Dynamics 365 CRM with Gamifics365!

Archives

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