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

Notifications

Announcements

No record found.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 81 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

#3
#ManoVerse Profile Picture

#ManoVerse 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans