Skip to main content

Notifications

Announcements

No record found.

How to Retrieve Records using FETCHXML using JavaScript in MSCRM or Dataverse

In this blog we will see how to How to Retrieve Records using FETCHXML using JavaScript in MSCRM or Dataverse


1. Prepare FetchXML ( Login to CRM or Dataverse then Go to Advance Find and Frame your Query and Download the FetchXML)
2. Consider am retrieving All Accounts

function retriveRecordusingFetchXML() {
    var fetchXml = `
<fetch>
  <entity name="account">
    <attribute name="accountid" />
    <attribute name="name" />
  </entity>
</fetch>`;

    var encodedFetchXML = encodeURIComponent(fetchXml);
    var fetchXmlRequest = "?fetchXml=" + encodedFetchXML;
    Xrm.WebApi.retrieveMultipleRecords("account", fetchXmlRequest).then(
        function success(result) {
            for (const record of result.entities) {
                var name = record.name;
            }
        },
        function (error) {
            var alertMessage = { text: error.message };
            Xrm.Navigation.openAlertDialog(alertMessage, null);
        }
    );
}

Use the Above Code to retrieve Record 

you can change the FetchXML based on your requirement.

This was originally posted here.

Comments

*This post is locked for comments