Skip to content

Commit a672b29

Browse files
committed
Added fetchXml to retrieve options
1 parent f89d4e1 commit a672b29

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

src/js/WebApiClient.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@
219219

220220
WebApiClient.Retrieve = function(parameters) {
221221
/// <summary>Retrieves records from CRM.</summary>
222-
/// <param name="parameters" type="Object">Object that contains 'entityName' or 'overriddenSetName', one of 'entityId', 'alternateKey' or 'queryParams' and optional 'headers'.</param>
222+
/// <param name="parameters" type="Object">Object that contains 'entityName' or 'overriddenSetName', one of 'entityId', 'alternateKey', 'fetchXml' or 'queryParams' and optional 'headers'.</param>
223223
/// <returns>Promise for sent request.</returns>
224224
var params = parameters || {};
225225

@@ -232,6 +232,9 @@
232232
if (params.entityId) {
233233
url += "(" + RemoveIdBrackets(params.entityId) + ")";
234234
}
235+
else if (params.fetchXml) {
236+
url += "?fetchXml=" + escape(params.fetchXml);
237+
}
235238
else if (params.alternateKey) {
236239
url += "(";
237240

src/spec/WebApiClientSpec.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,15 @@ describe("WebApiClient", function() {
3636
);
3737

3838
// Respond to Retrieve by id Request for account
39-
var retrieveAccountUrl = RegExp.escape(fakeUrl + "/api/data/v8.0/accounts(00000000-0000-0000-0000-000000000001)");
40-
xhr.respondWith("GET", new RegExp(retrieveAccountUrl, "g"),
39+
var retrieveAccountByIdUrl = RegExp.escape(fakeUrl + "/api/data/v8.0/accounts(00000000-0000-0000-0000-000000000001)");
40+
xhr.respondWith("GET", new RegExp(retrieveAccountByIdUrl, "g"),
41+
[200, { "Content-Type": "application/json" }, JSON.stringify(account)]
42+
);
43+
44+
// Respond to Retrieve by fetchXml Request for account
45+
var accountFetch = "%3Cfetch%20mapping%3D%27logical%27%3E%3Centity%20name%3D%27account%27%3E%3Cattribute%20name%3D%27accountid%27/%3E%3Cattribute%20name%3D%27name%27/%3E%3C/entity%3E%3C/fetch%3E";
46+
var retrieveAccountByFetchUrl = RegExp.escape(fakeUrl + "/api/data/v8.0/accounts?fetchXml=" + accountFetch);
47+
xhr.respondWith("GET", new RegExp(retrieveAccountByFetchUrl, "g"),
4148
[200, { "Content-Type": "application/json" }, JSON.stringify(account)]
4249
);
4350

@@ -319,6 +326,27 @@ describe("WebApiClient", function() {
319326

320327
xhr.respond();
321328
});
329+
330+
it("should retrieve by fetch", function(done){
331+
var fetchXml = "<fetch mapping='logical'>" +
332+
"<entity name='account'>" +
333+
"<attribute name='accountid'/>" +
334+
"<attribute name='name'/>" +
335+
"</entity>" +
336+
"</fetch>";
337+
338+
WebApiClient.Retrieve({entityName: "account", fetchXml: fetchXml})
339+
.then(function(response){
340+
expect(response).toEqual(account);
341+
})
342+
.catch(function(error) {
343+
expect(error).toBeUndefined();
344+
})
345+
// Wait for promise
346+
.finally(done);
347+
348+
xhr.respond();
349+
});
322350
});
323351

324352
describe("Update", function() {

0 commit comments

Comments
 (0)