retrieveRecord (Client API reference)
Syntax
Xrm.WebApi.retrieveRecord(entityLogicalName, id, options).then(successCallback, errorCallback);
Return Value
On success, returns a promise containing a JSON object with the retrieved attributes and their values.
Examples
Basic retrieve
Retrieves the name and revenue of an account record wwith record ID = 5531d753-95af-e711-a94e-000d3a11e605.
JavaScript
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 entities for an entity 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.
JavaScript
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
}
);
No comments:
Post a Comment