1
1
---
2
2
title : " Xrm.WebApi.online.execute (Client API reference) in model-driven apps| MicrosoftDocs"
3
- ms.date : 10/28/2019
3
+ ms.date : 08/11/2020
4
4
ms.service : powerapps
5
5
ms.topic : " reference"
6
6
applies_to : " Dynamics 365 (online)"
@@ -108,26 +108,26 @@ var Sdk = window.Sdk || {};
108
108
* @param {Object} opportunityClose - The opportunity close activity associated with this state change.
109
109
* @param {number} status - Status of the opportunity.
110
110
*/
111
- Sdk .WinOpportunityRequest = function (opportunityClose , status ) {
111
+ Sdk .WinOpportunityRequest = function (opportunityClose , status ) {
112
112
this .OpportunityClose = opportunityClose;
113
113
this .Status = status;
114
114
};
115
115
116
116
// NOTE: The getMetadata property should be attached to the function prototype instead of the
117
- // function object itself.
117
+ // function object itself.
118
118
Sdk .WinOpportunityRequest .prototype .getMetadata = function () {
119
119
return {
120
120
boundParameter: null ,
121
121
parameterTypes: {
122
122
" OpportunityClose" : {
123
123
" typeName" : " mscrm.opportunityclose" ,
124
124
" structuralProperty" : 5 // Entity Type
125
- },
125
+ },
126
126
" Status" : {
127
127
" typeName" : " Edm.Int32" ,
128
128
" structuralProperty" : 1 // Primitive Type
129
- }
130
- },
129
+ }
130
+ },
131
131
operationType: 0 , // This is an action. Use '1' for functions and '2' for CRUD
132
132
operationName: " WinOpportunity" ,
133
133
};
@@ -144,13 +144,13 @@ var winOpportunityRequest = new Sdk.WinOpportunityRequest(opportunityClose, 3);
144
144
145
145
// Use the request object to execute the function
146
146
Xrm .WebApi .online .execute (winOpportunityRequest).then (
147
- function (result ) {
147
+ function (result ) {
148
148
if (result .ok ) {
149
149
console .log (" Status: %s %s" , result .status , result .statusText );
150
150
// perform other operations as required;
151
151
}
152
152
},
153
- function (error ) {
153
+ function (error ) {
154
154
console .log (error .message );
155
155
// handle error conditions
156
156
}
@@ -202,25 +202,149 @@ Xrm.WebApi.online.execute(whoAmIRequest).then(
202
202
);
203
203
```
204
204
205
+ The following example demonstrates how to execute the < xref:Microsoft.Dynamics.CRM.CalculateRollupField > function:
206
+
207
+ ``` JavaScript
208
+ var Sdk = window .Sdk || {};
209
+
210
+ Sdk .CalculateRollupFieldRequest = function (target , fieldName ) {
211
+ this .Target = target;
212
+ this .FieldName = fieldName;
213
+ };
214
+
215
+ // NOTE: The getMetadata property should be attached to the function prototype instead of the
216
+ // function object itself.
217
+ Sdk .CalculateRollupFieldRequest .prototype .getMetadata = function () {
218
+ return {
219
+ boundParameter: null ,
220
+ parameterTypes: {
221
+ " Target" : {
222
+ " typeName" : " mscrm.crmbaseentity" ,
223
+ " structuralProperty" : 5
224
+ },
225
+ " FieldName" : {
226
+ " typeName" : " Edm.String" ,
227
+ " structuralProperty" : 1
228
+ }
229
+ },
230
+ operationType: 1 , // This is a function. Use '0' for actions and '2' for CRUD
231
+ operationName: " CalculateRollupField"
232
+ };
233
+ };
234
+
235
+ // Create variables to point to a quote record and to a specific field
236
+ var quoteId = {
237
+ " @odata.type" : " Microsoft.Dynamics.CRM.quote" ,
238
+ " quoteid" : " 7bb01e55-2394-ea11-a811-000d3ad97943"
239
+ };
240
+
241
+ // The roll-up field for which we want to force a re-calculation
242
+ var fieldName = " new_test_rollup" ;
243
+
244
+ // Create variable calculateRollupFieldRequest and pass those variables created above
245
+ var calculateRollupFieldRequest = new Sdk.CalculateRollupFieldRequest (quoteId, fieldName);
246
+
247
+ // Use the request object to execute the function
248
+ Xrm .WebApi .online .execute (calculateRollupFieldRequest).then (
249
+ function (result ) {
250
+ if (result .ok ) { // If the result was retrieved
251
+ result .json ().then ( // Convert the result to Json
252
+ function (response ) { // Do something with the response
253
+ console .log (" The response is: %s" , response);
254
+ });
255
+ }
256
+ },
257
+ function (error ) {
258
+ console .log (error .message );
259
+ // handle error conditions
260
+ });
261
+ ```
262
+
263
+ The following example demonstrates how to execute the < xref:Microsoft.Dynamics.CRM.RetrieveDuplicates > function:
264
+
265
+ ``` JavaScript
266
+ var Sdk = window .Sdk || {};
267
+
268
+ Sdk .RetrieveDuplicatesRequest = function (businessEntity , matchingEntityName , pagingInfo ) {
269
+ this .BusinessEntity = businessEntity;
270
+ this .MatchingEntityName = matchingEntityName;
271
+ this .PagingInfo = pagingInfo;
272
+
273
+ };
274
+
275
+ Sdk .RetrieveDuplicatesRequest .prototype .getMetadata = function () {
276
+ return {
277
+ boundParameter: null ,
278
+ parameterTypes: {
279
+ " BusinessEntity" : {
280
+ " typeName" : " mscrm.crmbaseentity" ,
281
+ " structuralProperty" : 5 // Entity Type
282
+ },
283
+ " MatchingEntityName" : {
284
+ " typeName" : " Edm.String" ,
285
+ " structuralProperty" : 1 // Primitive Type
286
+ },
287
+ " PagingInfo" : {
288
+ " typeName:" : " mscrm.PagingInfo" , // Complex Type
289
+ " structuralProperty" : 5
290
+ }
291
+ },
292
+ operationType: 1 , // This is a function. Use '0' for actions and '2' for CRUD
293
+ operationName: " RetrieveDuplicates" ,
294
+ };
295
+ };
296
+
297
+ // Create a variable to point to a contact record and with specific data in the needed fields
298
+ var contactRecord = {
299
+ " @odata.type" : " Microsoft.Dynamics.CRM.contact" ,
300
+ " firstname" : " Test" ,
301
+ " lastname" : " Account"
302
+ };
303
+
304
+ // Create a paging object to keep track of the current page and how many records we get per page
305
+ var pagingInfo = {
306
+ " PageNumber" : 1 ,
307
+ " Count" : 10
308
+ };
309
+
310
+ // Create the variable retrieveDuplicatesRequest to build the request
311
+ var retrieveDuplicatesRequest = new Sdk.RetrieveDuplicatesRequest (contactRecord, " contact" , pagingInfo);
312
+
313
+ // Use the request object to execute the function
314
+ Xrm .WebApi .online .execute (retrieveDuplicatesRequest).then (
315
+ function (result ) {
316
+ if (result .ok ) {
317
+ result .json ().then (
318
+ function (response ) {
319
+ console .log (" The response is: %s" , response);
320
+ });
321
+ }
322
+ },
323
+ function (error ) {
324
+ console .log (error .message );
325
+ // handle error conditions
326
+ });
327
+ ```
328
+
205
329
### Perform CRUD operations
206
330
207
331
#### Create a record
208
332
209
- The following example demonstrates how to perform a Create operation.
333
+ The following example demonstrates how to perform a create operation.
210
334
211
335
``` JavaScript
212
336
var Sdk = window .Sdk || {};
213
337
214
338
/**
215
339
* Request to execute a create operation
216
340
*/
217
- Sdk .CreateRequest = function (entityName , payload ) {
341
+ Sdk .CreateRequest = function (entityName , payload ) {
218
342
this .etn = entityName;
219
343
this .payload = payload;
220
344
};
221
345
222
346
// NOTE: The getMetadata property should be attached to the function prototype instead of the
223
- // function object itself.
347
+ // function object itself.
224
348
Sdk .CreateRequest .prototype .getMetadata = function () {
225
349
return {
226
350
boundParameter: null ,
@@ -237,13 +361,13 @@ var createRequest = new Sdk.CreateRequest("account", payload);
237
361
238
362
// Use the request object to execute the function
239
363
Xrm .WebApi .online .execute (createRequest).then (
240
- function (result ) {
364
+ function (result ) {
241
365
if (result .ok ) {
242
366
console .log (" Status: %s %s" , result .status , result .statusText );
243
367
// perform other operations as required;
244
368
}
245
369
},
246
- function (error ) {
370
+ function (error ) {
247
371
console .log (error .message );
248
372
// handle error conditions
249
373
}
@@ -252,21 +376,20 @@ Xrm.WebApi.online.execute(createRequest).then(
252
376
253
377
#### Retrieve a record
254
378
255
- The following example demonstrates how to perform a Retrieve operation.
379
+ The following example demonstrates how to perform a retrieve operation.
256
380
257
381
``` JavaScript
258
382
var Sdk = window .Sdk || {};
259
383
260
384
/**
261
385
* Request to execute a retrieve operation
262
386
*/
263
- Sdk .RetrieveRequest = function (entityReference , columns ) {
387
+ Sdk .RetrieveRequest = function (entityReference , columns ) {
264
388
this .entityReference = entityReference;
265
389
this .columns = columns;
266
390
};
267
-
268
391
// NOTE: The getMetadata property should be attached to the function prototype instead of the
269
- // function object itself.
392
+ // function object itself.
270
393
Sdk .RetrieveRequest .prototype .getMetadata = function () {
271
394
return {
272
395
boundParameter: null ,
@@ -285,27 +408,26 @@ var retrieveRequest = new Sdk.RetrieveRequest(entityReference, ["name"]);
285
408
286
409
// Use the request object to execute the function
287
410
Xrm .WebApi .online .execute (retrieveRequest).then (
288
- function (result ) {
411
+ function (result ) {
289
412
if (result .ok ) {
290
413
console .log (" Status: %s %s" , result .status , result .statusText );
291
414
result .json ().then (
292
- function (response ) {
415
+ function (response ) {
293
416
console .log (" Name: %s" , response .name );
294
417
// perform other operations as required;
295
418
});
296
419
}
297
420
},
298
- function (error ) {
421
+ function (error ) {
299
422
console .log (error .message );
300
423
// handle error conditions
301
424
}
302
425
);
303
-
304
426
```
305
427
306
428
#### Update a record
307
429
308
- The following example demonstrates how to perform a Update operation.
430
+ The following example demonstrates how to perform a update operation.
309
431
310
432
``` JavaScript
311
433
var Sdk = window .Sdk || {};
@@ -314,14 +436,14 @@ var Sdk = window.Sdk || {};
314
436
/**
315
437
* Request to execute an update operation
316
438
*/
317
- Sdk .UpdateRequest = function (entityName , entityId , payload ) {
439
+ Sdk .UpdateRequest = function (entityName , entityId , payload ) {
318
440
this .etn = entityName;
319
441
this .id = entityId;
320
442
this .payload = payload;
321
443
};
322
444
323
445
// NOTE: The getMetadata property should be attached to the function prototype instead of the
324
- // function object itself.
446
+ // function object itself.
325
447
Sdk .UpdateRequest .prototype .getMetadata = function () {
326
448
return {
327
449
boundParameter: null ,
@@ -339,13 +461,13 @@ var updateRequest = new Sdk.UpdateRequest("account", "d2b6c3f8-b0fa-e911-a812-00
339
461
340
462
// Use the request object to execute the function
341
463
Xrm .WebApi .online .execute (updateRequest).then (
342
- function (result ) {
464
+ function (result ) {
343
465
if (result .ok ) {
344
466
console .log (" Status: %s %s" , result .status , result .statusText );
345
467
// perform other operations as required;
346
468
}
347
469
},
348
- function (error ) {
470
+ function (error ) {
349
471
console .log (error .message );
350
472
// handle error conditions
351
473
}
@@ -354,20 +476,20 @@ Xrm.WebApi.online.execute(updateRequest).then(
354
476
355
477
#### Delete a record
356
478
357
- The following example demonstrates how to perform a Delete operation.
479
+ The following example demonstrates how to perform a delete operation.
358
480
359
481
``` JavaScript
360
482
var Sdk = window .Sdk || {};
361
483
362
484
/**
363
485
* Request to execute a delete operation
364
486
*/
365
- Sdk .DeleteRequest = function (entityReference ) {
487
+ Sdk .DeleteRequest = function (entityReference ) {
366
488
this .entityReference = entityReference;
367
489
};
368
490
369
491
// NOTE: The getMetadata property should be attached to the function prototype instead of the
370
- // function object itself.
492
+ // function object itself.
371
493
Sdk .DeleteRequest .prototype .getMetadata = function () {
372
494
return {
373
495
boundParameter: null ,
@@ -377,6 +499,7 @@ Sdk.DeleteRequest.prototype.getMetadata = function () {
377
499
};
378
500
};
379
501
};
502
+ };
380
503
381
504
// Construct request object from the metadata
382
505
var entityReference = {
@@ -387,13 +510,13 @@ var deleteRequest = new Sdk.DeleteRequest(entityReference);
387
510
388
511
// Use the request object to execute the function
389
512
Xrm .WebApi .online .execute (deleteRequest).then (
390
- function (result ) {
513
+ function (result ) {
391
514
if (result .ok ) {
392
515
console .log (" Status: %s %s" , result .status , result .statusText );
393
516
// perform other operations as required;
394
517
}
395
518
},
396
- function (error ) {
519
+ function (error ) {
397
520
console .log (error .message );
398
521
// handle error conditions
399
522
}
0 commit comments