How to retrieve multiple records in Dynamics 365 Online V 9.X using JavaScript WebAPI?

Below is the latest Syntax available to retrieve multiple records in Dynamics 365 Online V9.X using JavaScript,

Syntax:

Xrm.WebApi.retrieveMultipleRecords(entityLogicalName, options, maxPageSize).then(successCallback, errorCallback);

Parameters:

Name Type Required Description
entityLogicalName String Yes The entity logical name of the records you want to retrieve. For example: “account”.
options String No OData system query options or FetchXML query to retrieve your data.

·        Following system query options are supported: $select, $top, $filter, $expand, and $orderby.

·        To specify a FetchXML query, use the fetchXml attribute to specify the query.

NOTE: You must always use the $select system query option to limit the properties returned for an entity record by including a comma-separated list of property names. This is an important performance best practice. If properties aren’t specified using $select, all properties will be returned.

You specify the query options starting with ?. You can also specify multiple system query options by using & to separate the query options.

See examples later in this topic to see how you can define the options parameter for various retrieve multiple scenarios.

maxPageSize Number No Specify a positive number that indicates the number of entity records to be returned per page. If you do not specify this parameter, the default value is passed as 5000.

If the number of records being retrieved is more than the specified maxPageSize value, nextLink attribute in the returned promise object will contain a link to retrieve the next set of entities.

successCallback Function No A function to call when entity records are retrived. An object with the following attributes is passed to the function:1

·        entities: An array of JSON objects, where each object represents the retrieved entity record containing attributes and their values as key: value pairs. The Id of the entity record is retrieved by default.

·        nextLink: String. If the number of records being retrieved is more than the value specified in the maxPageSize paramter, this attribute returns the URL to return next set of records.

errorCallback Function No A function to call when the operation fails.

Return Value:
On success, returns a promise that contains an array of JSON objects (entities) containing the retrieved entity records and the nextLink attribute (optional) with the URL pointing to next set of records in case paging (maxPageSize) is specified and the record count returned exceeds the paging value.

Example:
Create a new Javascript Webresource (new_Account.js) and copy paste the below code in it and call it on OnLoad of the Account Form.

After that, open an existing account record.

function RetrieveAllAccountRecords() {
 var outputText = "Account Name\t\t\tPhone\n---------------------------------------------------\n";
 Xrm.WebApi.retrieveMultipleRecords("account", "?$select=name,telephone1").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);
 });
}

Output:

Dynamics 365 Retrieve All Records V9.X

Hope you have successfully retrieved all Account records using New Syntax.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s