Skip to content

Commit 77e501f

Browse files
responseParams is being cleared before parsing response - fix #79
1 parent cba7662 commit 77e501f

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,14 @@ In order to use DynamicsWebApi inside Dynamics 365 you need to download a browse
9292
Upload a script as a JavaScript Web Resource, place on the entity form or refer to it in your HTML Web Resource and then initialize the main object:
9393

9494
```js
95-
//DynamicsWebApi makes calls to Web API v8.0 if a configuration not set
95+
//DynamicsWebApi makes calls to Web API v8.0 if a configuration is not set
9696
var dynamicsWebApi = new DynamicsWebApi();
9797

9898
dynamicsWebApi.executeUnboundFunction("WhoAmI").then(function (response) {
99-
Xrm.Utility.alertDialog('Hello Dynamics 365! My id is: ' + response.UserId);
99+
Xrm.Navigation.openAlertDialog({
100+
text: "Hello Dynamics 365! My id is: " + response.UserId,
101+
title: "DynamicsWebApi Test"
102+
});
100103
}).catch(function(error){
101104
console.log(error.message);
102105
});
@@ -159,7 +162,7 @@ function acquireToken(dynamicsWebApiCallback){
159162

160163
//create DynamicsWebApi object
161164
var dynamicsWebApi = new DynamicsWebApi({
162-
webApiUrl: 'https://myorg.api.crm.dynamics.com/api/data/v9.0/',
165+
webApiUrl: 'https://myorg.api.crm.dynamics.com/api/data/v9.1/',
163166
onTokenRefresh: acquireToken
164167
});
165168

@@ -177,14 +180,14 @@ To initialize a new instance of DynamicsWebApi with a configuration object, plea
177180
#### Web browser
178181

179182
```js
180-
var dynamicsWebApi = new DynamicsWebApi({ webApiVersion: '9.0' });
183+
var dynamicsWebApi = new DynamicsWebApi({ webApiVersion: '9.1' });
181184
```
182185

183186
#### Node.js
184187

185188
```js
186189
var dynamicsWebApi = new DynamicsWebApi({
187-
webApiUrl: 'https://myorg.api.crm.dynamics.com/api/data/v9.0/',
190+
webApiUrl: 'https://myorg.api.crm.dynamics.com/api/data/v9.1/',
188191
onTokenRefresh: acquireToken
189192
});
190193
```
@@ -193,7 +196,7 @@ You can set a configuration dynamically if needed:
193196

194197
```js
195198
//or can be set dynamically
196-
dynamicsWebApi.setConfig({ webApiVersion: '8.2' });
199+
dynamicsWebApi.setConfig({ webApiVersion: '9.1' });
197200
```
198201

199202
#### Configuration Parameters
@@ -207,7 +210,7 @@ onTokenRefresh | Function | A callback function that triggered when DynamicsWebA
207210
returnRepresentation | Boolean | Defaults Prefer header with value "return=representation". Use this property to return just created or updated entity in a single request.
208211
timeout | Number | Sets a number of milliseconds before a request times out.
209212
useEntityNames | Boolean | `v.1.4.0+` Indicates whether to use entity logical names instead of collection logical names during requests.
210-
webApiUrl | String | A complete URL string to Web API. Example of the URL: "https://myorg.api.crm.dynamics.com/api/data/v8.2/". If it is specified then webApiVersion property will not be used even if it is not empty.
213+
webApiUrl | String | A complete URL string to Web API. Example of the URL: "https://myorg.api.crm.dynamics.com/api/data/v9.1/". If it is specified then webApiVersion property will not be used even if it is not empty.
211214
webApiVersion | String | Version of the Web API. Default version is "8.0".
212215

213216
Configuration property `webApiVersion` is required only when DynamicsWebApi used inside CRM.

lib/requests/http.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ var httpRequest = function (options) {
8585
status: res.statusCode
8686
};
8787

88+
responseParams.length = 0;
89+
8890
successCallback(response);
8991
break;
9092
}
@@ -111,14 +113,14 @@ var httpRequest = function (options) {
111113
}
112114
}
113115

116+
responseParams.length = 0;
117+
114118
errorCallback(ErrorHelper.handleHttpError(crmError, {
115119
status: res.statusCode, statusText: request.statusText, statusMessage: res.statusMessage, headers: res.headers
116120
}));
117121

118122
break;
119123
}
120-
121-
responseParams.length = 0;
122124
});
123125
});
124126

lib/requests/xhr.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ var xhrRequest = function (options) {
4444
status: request.status
4545
};
4646

47+
responseParams.length = 0;
48+
request = null;
49+
4750
successCallback(response);
51+
4852
break;
4953
}
5054
default: // All other statuses are error cases.
@@ -68,17 +72,19 @@ var xhrRequest = function (options) {
6872
}
6973
}
7074

71-
errorCallback(ErrorHelper.handleHttpError(error, {
75+
var errorResponse = {
7276
status: request.status,
7377
statusText: request.statusText,
7478
headers: headers
75-
}));
79+
}
80+
81+
responseParams.length = 0;
82+
request = null;
83+
84+
errorCallback(ErrorHelper.handleHttpError(error, errorResponse));
7685

7786
break;
7887
}
79-
80-
request = null;
81-
responseParams.length = 0;
8288
}
8389
};
8490

0 commit comments

Comments
 (0)