In my previous article, I have explained about How to retrieve multiple records using Odata Query in Dynamics 365 Online V 9.X using JavaScript WebAPI?
And now i will use the same example, which i used in my earlier article mentioned in the above link and retrieve multiple Account records using FetchXML query.
Syntax:
You can format the FetchXML using FetchXML Formatter Online.
Xrm.WebApi.retrieveMultipleRecords(entityLogicalName, options).then(successCallback, errorCallback);
Under options parameter pass “?fetchXml=” +encodeURIComponent(“Insert required FetchXML“)
Code: Configure the below code on Onload of Account Form and see the Output.
function RetrieveAllAccountRecords() {
var accountFetchXML = "<fetch mapping='logical' version='1.0' output-format='xml-platform' distinct='false'>" +
" <entity name='account'>" +
" <attribute name='name' />" +
" <attribute name='primarycontactid' />" +
" <attribute name='telephone1' />" +
" <attribute name='accountid' />" +
" <order descending='false' attribute='name' />" +
" </entity>" +
"</fetch>";
accountFetchXML = "?fetchXml=" + encodeURIComponent(accountFetchXML);
var outputText = "Account Name\t\t\tPhone\n---------------------------------------------------\n";
Xrm.WebApi.retrieveMultipleRecords("account", accountFetchXML).then(
function success(result) {
for (var accountRecordsCount = 0; accountRecordsCount < result.entities.length; accountRecordsCount++) {
outputText += result.entities[accountRecordsCount].name + "\t\t" + result.entities[accountRecordsCount].telephone1 + "\n";
}
Xrm.Utility.alertDialog(outputText, null);
},
function (error) {
// Handle error conditions
Xrm.Utility.alertDialog(error.message, null);
});
}
Hope you have successfully retrieve multiple records using FetchXML and WebAPI.
Good read.
LikeLike