retrieveRecord (Client API reference)
Retrieves a table record.
Syntax
Xrm.WebApi.retrieveRecord(entityLogicalName, id, options).then(successCallback, errorCallback);
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| entityLogicalName | String | Yes | The table logical name of the record you want to retrieve. For example: "account". |
| id | String | Yes | GUID of the table record you want to retrieve. |
| options | String | No | OData system query options, $select and $expand, to retrieve your data.
You specify the query options starting with ?$select=name&$expand=primarycontactid($select=contactid,fullname)
See examples later in this article to see how you can define the |
| successCallback | Function | No | A function to call when a record is retrieved. A JSON object with the retrieved properties and values will be passed to the function. |
| errorCallback | Function | No | A function to call when the operation fails. |
Return Value
On success, returns a promise containing a JSON object with the retrieved columns and their values.
Examples
Basic retrieve
Retrieves the name and revenue of an account record with record ID = 5531d753-95af-e711-a94e-000d3a11e605.
Xrm.WebApi.retrieveRecord("account", "a8a19cdd-88df-e311-b8e5-6c3be5a8b200", "?$select=name,revenue").then(
function success(result) {
console.log("Retrieved values: Name: " + result.name + ", Revenue: " + result.revenue);
// perform operations on record retrieval
},
function (error) {
console.log(error.message);
// handle error conditions
}
);
The above example displays the following in your console; you might see other values depending on your data:
Retrieved values: Name: Sample Account, Revenue: 5000000
Retrieve related tables for a table instance by expanding single-valued navigation properties
The following example demonstrates how to retrieve the contact for an account record with record ID = a8a19cdd-88df-e311-b8e5-6c3be5a8b200. For the related contact record, we are only retrieving the contactid and fullname properties.
Xrm.WebApi.retrieveRecord("account", "a8a19cdd-88df-e311-b8e5-6c3be5a8b200", "?$select=name&$expand=primarycontactid($select=contactid,fullname)").then(
function success(result) {
console.log("Retrieved values: Name: " + result.name + ", Primary Contact ID: " + result.primarycontactid.contactid +
", Primary Contact Name: " + result.primarycontactid.fullname);
// perform operations on record retrieval
},
function (error) {
console.log(error.message);
// handle error conditions
}
);
The above example displays the following in your console; you might see other values depending on your data:
Retrieved values: Name: Adventure Works, Primary Contact ID: 49a0e5b9-88df-e311-b8e5-6c3be5a8b200, Primary Contact Name: Adrian Dumitrascu