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

Web API code to get data from EntityDefination using js.

(0) ShareShare
ReportReport
Posted on by 10

Hello All,

function testMethd() {
Xrm.WebApi.online.retrieveMultipleRecords("entitydefinition", "?$filter=entitysetname eq 'contacts'").then(
function success(results) {
for (var i = 0; i < results.entities.length; i++) {
debugger;
alert(results.entities.length);
}
},
function (error) {
Xrm.Utility.alertDialog(error.message);
}
);
}

I'm trying to fetch the data from EntityDefination metadata but it's not working.

Can you please help me?

Thank you

I have the same question (0)
  • Suggested answer
    Jean Joel Kakou Profile Picture
    Microsoft Employee on at

    Hello Sneba,  

    Thank you for your post.

    You can find more example how to get data from an Entity:

    docs.microsoft.com/.../query-data-web-api

    If you are using RetrieveMultiple, the syntax mention that you have to add the EntityLogicalName of the entity:

    docs.microsoft.com/.../retrievemultiplerecords

    docs.microsoft.com/.../retrievemultiplerecords

    Sample example:

    Xrm.WebApi.retrieveMultipleRecords("account", "?$select=name&$top=3").then(

       function success(result) {

           for (var i = 0; i < result.entities.length; i++) {

               console.log(result.entities[i]);

           }                    

           // perform additional operations on retrieved records

       },

       function (error) {

           console.log(error.message);

           // handle error conditions

       }

    );

  • Sneha Patil Profile Picture
    10 on at

    Hi Jean Joel Kakou,

    Thank you for your response.

    But I want to fetch data from EntityDefinition table. I'm getting data on Poastman using query {{webapiurl}}/EntityDefinitions?$filter=EntitySetName eq 'contacts' but unable to get data using Xrm.WebApi

  • Jean Joel Kakou Profile Picture
    Microsoft Employee on at

    Hello Sneba,  

    In this case you will have to call the request like this sample below:

    function QueryCRM(executionContext) {

    formContext = executionContext.getFormContext();

    var ClientUrl= Xrm.Utility.getGlobalContext().getClientUrl();

    var url = ClientUrl+"/api/data/v9.1/EntityDefinitions?$filter=EntitySetName eq 'accounts'";

    var req = new XMLHttpRequest();

    req.open("GET", url, false);

    req.setRequestHeader("Accept", "application/json");

    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");

    req.send();

    if (req.readyState == 4 /* complete */) {

    //Success

    if (req.status == 200) {

    console.log(req.responseText);

    }

    //Failure

    else {

    console.log("Error: " + req.responseText);

    }

    }

    }

    Source: carldesouza.com/.../

  • Sneha Patil Profile Picture
    10 on at

    Hi Jean Joel Kakou,

    I used the same method to fetch data. But is it possible to fetch data using Xrm.WebApi? I have a requirement of same.

    Thank you

  • Jean Joel Kakou Profile Picture
    Microsoft Employee on at

    I dont think so, Xrm.WebApi will manipulate records and you want to get metadata of the entity definition

    docs.microsoft.com/.../xrm-webapi

    docs.microsoft.com/.../execute

  • Sneha Patil Profile Picture
    10 on at

    Thank you Jean Joel Kakou for your response.

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 March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 196 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 129

#3
CU11031447-0 Profile Picture

CU11031447-0 100

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans