Skip to content

Commit 2b007c1

Browse files
authored
Merge pull request #7437 from MicrosoftDocs/pakempar/updateRetriveMultipleExample
Add a fetchXML based example for retrieve multiple with lookup filter
2 parents 614a404 + 295447e commit 2b007c1

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

powerapps-docs/developer/model-driven-apps/clientapi/reference/Xrm-WebApi/retrieveMultipleRecords.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: "retrieveMultipleRecords (Client API reference) in model-driven apps| Mic
33
description: Includes description and supported parameters for the retrieveMultipleRecords method.
44
author: adrianorth
55
ms.author: aorth
6-
ms.date: 04/19/2022
6+
ms.date: 12/15/2022
77
ms.reviewer: jdaly
88
ms.topic: reference
99
search.audienceType:
@@ -219,6 +219,40 @@ Xrm.WebApi.retrieveMultipleRecords("account", "?$select=name,primarycontactid&$f
219219
}
220220
);
221221
```
222+
223+
#### Using FetchXML to retrieve or filter by lookup properties (online and offline scenario)
224+
225+
You can use the `FetchXML` parameter while online or offline to retrieve the `name` and `primarycontactid` property for account records that have a primary contact that matches a condition:
226+
227+
```JavaScript
228+
var fetchXml = `?fetchXml=
229+
<fetch mapping='logical'>
230+
<entity name='account'>
231+
<attribute name='name'/>
232+
<attribute name='primarycontactid'/>
233+
<link-entity name='contact' from='contactid' to='primarycontactid'>
234+
<filter type='and'>
235+
<condition attribute='lastname' operator='eq' value='Contoso'/>
236+
</filter>
237+
</link-entity>
238+
</entity>
239+
</fetch>`;
240+
241+
Xrm.WebApi.retrieveMultipleRecords("account", fetchXml).then(
242+
function success(result) {
243+
for (var i = 0; i < result.entities.length; i++) {
244+
console.log(result.entities[i]);
245+
}
246+
247+
// perform additional operations on retrieved records
248+
},
249+
function (error) {
250+
console.log(error.message);
251+
// handle error conditions
252+
}
253+
);
254+
```
255+
222256
### Specify the number of tables to return in a page
223257

224258
The following example demonstrates the use of the `maxPageSize` parameter to specify the number of records (3) to be displayed in a page.

0 commit comments

Comments
 (0)