Skip to content

Commit b916dfd

Browse files
committed
Leaving out hyphens in alternate key urls if values are numbers, this fixes #21
1 parent 70a916c commit b916dfd

File tree

7 files changed

+59
-20
lines changed

7 files changed

+59
-20
lines changed

docs/WebApiClient.Core.js.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,8 +654,13 @@ <h1 class="page-title">Source: WebApiClient.Core.js</h1>
654654

655655
for (var i = 0; i &lt; params.alternateKey.length; i++) {
656656
var key = params.alternateKey[i];
657+
var value = key.value;
658+
659+
if (typeof(key.value) !== "number") {
660+
value = "'" + key.value + "'";
661+
}
657662

658-
url += key.property + "='" + key.value + "'";
663+
url += key.property + "=" + value;
659664

660665
if (i + 1 === params.alternateKey.length) {
661666
url += ")";
@@ -1083,7 +1088,7 @@ <h4 class="modal-title">Search results</h4>
10831088
<span class="jsdoc-message">
10841089
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.3</a>
10851090

1086-
on Mon Jul 31st 2017
1091+
on Wed Oct 18th 2017
10871092

10881093
using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
10891094
</span>

docs/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787

8888
<section class="readme-section">
8989
<article><h1>Dynamics CRM JavaScript Web API Client</h1><p><a href="https://travis-ci.org/DigitalFlow/Xrm-WebApi-Client"><img src="https://travis-ci.org/DigitalFlow/Xrm-WebApi-Client.svg?branch=master" alt="Build Status"></a> <a href="https://coveralls.io/github/DigitalFlow/Xrm-WebApi-Client?branch=master"><img src="https://coveralls.io/repos/github/DigitalFlow/Xrm-WebApi-Client/badge.svg?branch=master" alt="Coverage Status"></a> <a href="http://packagequality.com/#?package=xrm-webapi-client"><img src="http://npm.packagequality.com/shield/xrm-webapi-client.svg" alt="Package Quality"></a> <a href="http://npm-stats.com/~packages/xrm-webapi-client"><img src="https://img.shields.io/npm/dt/xrm-webapi-client.svg" alt="npm downloads"></a> <a href="https://gitter.im/DigitalFlow/Xrm-WebApi-Client?utm_source=badge&amp;utm_medium=badge&amp;utm_campaign=pr-badge&amp;utm_content=badge"><img src="https://badges.gitter.im/Join%20Chat.svg" alt="Join the chat at https://gitter.im/DigitalFlow/Xrm-WebApi-Client"></a></p>
90-
<p>This is a framework for easing working with the Dynamics CRM WebApi using JavaScript.<br>It uses the awesome <a href="https://github.com/petkaantonov/bluebird">BlueBird</a> framework for handling requests asynchronously based on promises.<br>The framework is supposed to be executed on CRM forms or on CRM web ressources, where the CRM context is available.<br>For running from custom web resources, be sure that the GetGlobalContext function is available, as the client will try to retrieve the context on its own.</p>
90+
<p>This is a framework for easing working with the Dynamics CRM WebApi using JavaScript.<br>It uses the awesome <a href="https://github.com/petkaantonov/bluebird">BlueBird</a> framework for handling requests asynchronously based on promises.<br>The framework is supposed to be executed on CRM forms or on CRM web ressources, where the CRM context is available.<br>In addition to that, usage for single page applications outside of CRM is also possible.<br>For running from custom web resources, be sure that the GetGlobalContext function is available, as the client will try to retrieve the context on its own.</p>
9191
<h1>Index</h1><ul>
9292
<li><a href="#dynamics-crm-javascript-web-api-client">Dynamics CRM JavaScript Web API Client</a><ul>
9393
<li><a href="#requirements">Requirements</a><ul>
@@ -693,7 +693,7 @@ <h4 class="modal-title">Search results</h4>
693693
<span class="jsdoc-message">
694694
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.3</a>
695695

696-
on Mon Jul 31st 2017
696+
on Wed Oct 18th 2017
697697

698698
using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
699699
</span>

docs/module-WebApiClient.html

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,7 @@ <h6 class="method-params-label method-subparams-label">Properties</h6>
12961296
<ul class="dummy">
12971297
<li>
12981298
<a href="WebApiClient.Core.js.html">WebApiClient.Core.js</a>,
1299-
<a href="WebApiClient.Core.js.html#sunlight-1-line-785">line 785</a>
1299+
<a href="WebApiClient.Core.js.html#sunlight-1-line-790">line 790</a>
13001300
</li>
13011301
</ul>
13021302
</dd>
@@ -1463,7 +1463,7 @@ <h5>Parameters:</h5>
14631463
<ul class="dummy">
14641464
<li>
14651465
<a href="WebApiClient.Core.js.html">WebApiClient.Core.js</a>,
1466-
<a href="WebApiClient.Core.js.html#sunlight-1-line-644">line 644</a>
1466+
<a href="WebApiClient.Core.js.html#sunlight-1-line-649">line 649</a>
14671467
</li>
14681468
</ul>
14691469
</dd>
@@ -1815,7 +1815,7 @@ <h6 class="method-params-label method-subparams-label">Properties</h6>
18151815
<ul class="dummy">
18161816
<li>
18171817
<a href="WebApiClient.Core.js.html">WebApiClient.Core.js</a>,
1818-
<a href="WebApiClient.Core.js.html#sunlight-1-line-671">line 671</a>
1818+
<a href="WebApiClient.Core.js.html#sunlight-1-line-676">line 676</a>
18191819
</li>
18201820
</ul>
18211821
</dd>
@@ -2218,7 +2218,7 @@ <h6 class="method-params-label method-subparams-label">Properties</h6>
22182218
<ul class="dummy">
22192219
<li>
22202220
<a href="WebApiClient.Core.js.html">WebApiClient.Core.js</a>,
2221-
<a href="WebApiClient.Core.js.html#sunlight-1-line-761">line 761</a>
2221+
<a href="WebApiClient.Core.js.html#sunlight-1-line-766">line 766</a>
22222222
</li>
22232223
</ul>
22242224
</dd>
@@ -2829,7 +2829,7 @@ <h6 class="method-params-label method-subparams-label">Properties</h6>
28292829
<ul class="dummy">
28302830
<li>
28312831
<a href="WebApiClient.Core.js.html">WebApiClient.Core.js</a>,
2832-
<a href="WebApiClient.Core.js.html#sunlight-1-line-824">line 824</a>
2832+
<a href="WebApiClient.Core.js.html#sunlight-1-line-829">line 829</a>
28332833
</li>
28342834
</ul>
28352835
</dd>
@@ -3092,7 +3092,7 @@ <h6 class="method-params-label method-subparams-label">Properties</h6>
30923092
<ul class="dummy">
30933093
<li>
30943094
<a href="WebApiClient.Core.js.html">WebApiClient.Core.js</a>,
3095-
<a href="WebApiClient.Core.js.html#sunlight-1-line-865">line 865</a>
3095+
<a href="WebApiClient.Core.js.html#sunlight-1-line-870">line 870</a>
30963096
</li>
30973097
</ul>
30983098
</dd>
@@ -3387,7 +3387,7 @@ <h6 class="method-params-label method-subparams-label">Properties</h6>
33873387
<ul class="dummy">
33883388
<li>
33893389
<a href="WebApiClient.Core.js.html">WebApiClient.Core.js</a>,
3390-
<a href="WebApiClient.Core.js.html#sunlight-1-line-914">line 914</a>
3390+
<a href="WebApiClient.Core.js.html#sunlight-1-line-919">line 919</a>
33913391
</li>
33923392
</ul>
33933393
</dd>
@@ -3504,7 +3504,7 @@ <h4 class="name" id=".GetApiUrl"><span class="type-signature">&lt;static> </span
35043504
<ul class="dummy">
35053505
<li>
35063506
<a href="WebApiClient.Core.js.html">WebApiClient.Core.js</a>,
3507-
<a href="WebApiClient.Core.js.html#sunlight-1-line-661">line 661</a>
3507+
<a href="WebApiClient.Core.js.html#sunlight-1-line-666">line 666</a>
35083508
</li>
35093509
</ul>
35103510
</dd>
@@ -4270,7 +4270,7 @@ <h6 class="method-params-label method-subparams-label">Properties</h6>
42704270
<ul class="dummy">
42714271
<li>
42724272
<a href="WebApiClient.Core.js.html">WebApiClient.Core.js</a>,
4273-
<a href="WebApiClient.Core.js.html#sunlight-1-line-695">line 695</a>
4273+
<a href="WebApiClient.Core.js.html#sunlight-1-line-700">line 700</a>
42744274
</li>
42754275
</ul>
42764276
</dd>
@@ -4533,7 +4533,7 @@ <h6 class="method-params-label method-subparams-label">Properties</h6>
45334533
<ul class="dummy">
45344534
<li>
45354535
<a href="WebApiClient.Core.js.html">WebApiClient.Core.js</a>,
4536-
<a href="WebApiClient.Core.js.html#sunlight-1-line-886">line 886</a>
4536+
<a href="WebApiClient.Core.js.html#sunlight-1-line-891">line 891</a>
45374537
</li>
45384538
</ul>
45394539
</dd>
@@ -4906,7 +4906,7 @@ <h6 class="method-params-label method-subparams-label">Properties</h6>
49064906
<ul class="dummy">
49074907
<li>
49084908
<a href="WebApiClient.Core.js.html">WebApiClient.Core.js</a>,
4909-
<a href="WebApiClient.Core.js.html#sunlight-1-line-599">line 599</a>
4909+
<a href="WebApiClient.Core.js.html#sunlight-1-line-604">line 604</a>
49104910
</li>
49114911
</ul>
49124912
</dd>
@@ -5297,7 +5297,7 @@ <h6 class="method-params-label method-subparams-label">Properties</h6>
52975297
<ul class="dummy">
52985298
<li>
52995299
<a href="WebApiClient.Core.js.html">WebApiClient.Core.js</a>,
5300-
<a href="WebApiClient.Core.js.html#sunlight-1-line-736">line 736</a>
5300+
<a href="WebApiClient.Core.js.html#sunlight-1-line-741">line 741</a>
53015301
</li>
53025302
</ul>
53035303
</dd>
@@ -5415,7 +5415,7 @@ <h4 class="modal-title">Search results</h4>
54155415
<span class="jsdoc-message">
54165416
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.3</a>
54175417

5418-
on Mon Jul 31st 2017
5418+
on Wed Oct 18th 2017
54195419

54205420
using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
54215421
</span>

docs/modules.list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ <h4 class="modal-title">Search results</h4>
192192
<span class="jsdoc-message">
193193
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.3</a>
194194

195-
on Mon Jul 31st 2017
195+
on Wed Oct 18th 2017
196196

197197
using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
198198
</span>

docs/quicksearch.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/js/WebApiClient.Core.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,8 +582,13 @@
582582

583583
for (var i = 0; i < params.alternateKey.length; i++) {
584584
var key = params.alternateKey[i];
585+
var value = key.value;
586+
587+
if (typeof(key.value) !== "number") {
588+
value = "'" + key.value + "'";
589+
}
585590

586-
url += key.property + "='" + key.value + "'";
591+
url += key.property + "=" + value;
587592

588593
if (i + 1 === params.alternateKey.length) {
589594
url += ")";

src/spec/WebApiClientSpec.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ describe("WebApiClient", function() {
124124
[200, { "Content-Type": "application/json" }, JSON.stringify(contact)]
125125
);
126126

127+
// Respond to Retrieve Request for contact with alternate key that contains numbers
128+
var retrieveByAlternateKeyNumberUrl = RegExp.escape(fakeUrl + "/api/data/v8.0/contacts(firstname='Joe',contactnumber=1)");
129+
xhr.respondWith("GET", new RegExp(retrieveByAlternateKeyNumberUrl),
130+
[200, { "Content-Type": "application/json" }, JSON.stringify(contact)]
131+
);
132+
127133
// Respond to update Request for contact with alternate key
128134
xhr.respondWith("PATCH", new RegExp(retrieveByAlternateKeyUrl),
129135
[204, { "Content-Type": "application/json" }, JSON.stringify(successMock)]
@@ -611,6 +617,29 @@ describe("WebApiClient", function() {
611617
xhr.respond();
612618
});
613619

620+
it("should not use hyphens in alternate key url value if value is number", function(done){
621+
WebApiClient.Retrieve(
622+
{
623+
entityName: "contact",
624+
alternateKey:
625+
[
626+
{ property: "firstname", value: "Joe" },
627+
{ property: "contactnumber", value: 1}
628+
]
629+
})
630+
.then(function(response){
631+
expect(response).toEqual(contact);
632+
})
633+
.catch(function(error) {
634+
expect(error).toBeUndefined();
635+
})
636+
// Wait for promise
637+
.finally(done);
638+
639+
xhr.respond();
640+
});
641+
642+
614643
it("should retrieve by fetch", function(done){
615644
var fetchXml = "<fetch mapping='logical'>" +
616645
"<entity name='account'>" +

0 commit comments

Comments
 (0)