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

How to retrieve entity metadata using Xrm.Utility.getEntityMetadata()

By Inogic | October 27, 2020
0 Comment

Introduction

Currently, we need to create http requests to retrieve the metadata of the entity or attributes of any entity. But now, Dynamics 365 introduced a Web API method i.e Xrm.Utility.getEntityMetadata() which helps you retrieve any entity metadata easily without creating any http requests. Please find below two examples to understand this method in detail:

1. Retrieve whole entity metadata

Let’s take one example, we want to check if the current entity is activity entity or not. For this query, you can simply use Xrm.Utility.getEntityMetadata, you need to just pass the entity logical name of the entity which you want to retrieve the metadata for, as shown below:

Xrm.Utility.getEntityMetadata(“account”, []).then(

function(entityMetadata){

//check for entity metadata

If(entityMetadata!=undefined){

//declare one flag which indicate current entity is activity entity

var isActivityEntity = false;

//check for IsActivity attribute

if (entityMetadata.IsActivity != undefined) {

//check current entity is activity entity using IsActivity attribute

if (entityMetadata.IsActivity == true) {

//set flag to true as current entity is Activity entity

isActivityEntity = true;

} else {

//set flag to false as current entity is not Activity entity

isActivityEntity = true;

}

}

}

}, function(e){

//error

alert(e.error.message);

});

Note: We pass the second parameter is empty [] to getEntityMetadata method because in the above example we need to retrieve all metadata of the Account entity.

After running the below code, we will get all the metadata of that entity such as logical name, entity set name, as shown in the below screenshot.

2. Retrieve metadata of selected attribute of any entity

Now, we want to retrieve any attribute metadata of any entity that you want in Dynamics 365. Let’s take one example; we want to retrieve metadata of the industry field of Account entity using the getEntityMetadata method. In this scenario, you need to pass those entity names and attributes list for which you want to retrieve metadata, as shown below.

Xrm.Utility.getEntityMetadata(“account”, [“industrycode”]).then(

function (entityMetadata) {

//check for attribute entity metadata

if (entityMetadata != undefined && entityMetadata.Attributes != undefined && entityMetadata.Attributes._collection != undefined) {

//check for industry type option set

if (entityMetadata.Attributes._collection[“industrycode”]) {

//get option set data

var industryCodeOptionSetData = entityMetadata.Attributes._collection[“industrycode”].OptionSet;

}

}

}, function(e){

//error call back

alert(e.error.message);

});

After running the above code you will get all options data in the industry field Option Set, as shown in the below screenshot:

How to retrieve entity metadata using Xrm.Utility.getEntityMetadata

Conclusion

With help of Xrm.Utility.getEntityMetadata() method you can retrieve metadata of any entity or metadata of any attributes of that entity, you no longer need to create an http request to achieve this.

Category: Dynamics 365 Dynamics 365 v9 Dynamics CRM Dynamics CRM 2016 Tags: Dynamics 365 CRM, Dynamics CRM, Entity, metadata, Retrive metadata, XRM, Xrm.Utility
Post navigation
← Daily, Weekly, Monthly or Annually – Schedule and Automate Bills Generation in Dynamics 365 CRM/Power Apps with Recurring Billing Manager! Match the theme of Dynamics 365 App in Power Apps Control Framework – Part 1 →

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

  • Tooltip on Search for Entity records in Dynamics 365
  • Inogic apps on the popular GYDE365-Discover platform – Find the right Dynamics 365 CRM app!
  • Outsourcing Microsoft Dynamics 365 CRM and Power Platform Development – All under one roof!
  • Exploring Power Apps Ideas (PREVIEW) feature in Canvas App Designer
  • Add or Edit table relationships using the Model-Driven Application form designer

Archives

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