Skip to content

Commit 13e5389

Browse files
authored
Merge pull request MicrosoftDocs#3248 from MicrosoftDocs/master
taking changes to live
2 parents 06d4e11 + 27eeee9 commit 13e5389

File tree

3 files changed

+222
-31
lines changed

3 files changed

+222
-31
lines changed

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

Lines changed: 154 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
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
44
ms.service: powerapps
55
ms.topic: "reference"
66
applies_to: "Dynamics 365 (online)"
@@ -108,26 +108,26 @@ var Sdk = window.Sdk || {};
108108
* @param {Object} opportunityClose - The opportunity close activity associated with this state change.
109109
* @param {number} status - Status of the opportunity.
110110
*/
111-
Sdk.WinOpportunityRequest = function (opportunityClose, status) {
111+
Sdk.WinOpportunityRequest = function(opportunityClose, status) {
112112
this.OpportunityClose = opportunityClose;
113113
this.Status = status;
114114
};
115115

116116
// NOTE: The getMetadata property should be attached to the function prototype instead of the
117-
// function object itself.
117+
// function object itself.
118118
Sdk.WinOpportunityRequest.prototype.getMetadata = function () {
119119
return {
120120
boundParameter: null,
121121
parameterTypes: {
122122
"OpportunityClose": {
123123
"typeName": "mscrm.opportunityclose",
124124
"structuralProperty": 5 // Entity Type
125-
},
125+
},
126126
"Status": {
127127
"typeName": "Edm.Int32",
128128
"structuralProperty": 1 // Primitive Type
129-
}
130-
},
129+
}
130+
},
131131
operationType: 0, // This is an action. Use '1' for functions and '2' for CRUD
132132
operationName: "WinOpportunity",
133133
};
@@ -144,13 +144,13 @@ var winOpportunityRequest = new Sdk.WinOpportunityRequest(opportunityClose, 3);
144144

145145
// Use the request object to execute the function
146146
Xrm.WebApi.online.execute(winOpportunityRequest).then(
147-
function (result) {
147+
function(result) {
148148
if (result.ok) {
149149
console.log("Status: %s %s", result.status, result.statusText);
150150
// perform other operations as required;
151151
}
152152
},
153-
function (error) {
153+
function(error) {
154154
console.log(error.message);
155155
// handle error conditions
156156
}
@@ -202,25 +202,149 @@ Xrm.WebApi.online.execute(whoAmIRequest).then(
202202
);
203203
```
204204

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+
205329
### Perform CRUD operations
206330

207331
#### Create a record
208332

209-
The following example demonstrates how to perform a Create operation.
333+
The following example demonstrates how to perform a create operation.
210334

211335
```JavaScript
212336
var Sdk = window.Sdk || {};
213337

214338
/**
215339
* Request to execute a create operation
216340
*/
217-
Sdk.CreateRequest = function (entityName, payload) {
341+
Sdk.CreateRequest = function(entityName, payload) {
218342
this.etn = entityName;
219343
this.payload = payload;
220344
};
221345

222346
// NOTE: The getMetadata property should be attached to the function prototype instead of the
223-
// function object itself.
347+
// function object itself.
224348
Sdk.CreateRequest.prototype.getMetadata = function () {
225349
return {
226350
boundParameter: null,
@@ -237,13 +361,13 @@ var createRequest = new Sdk.CreateRequest("account", payload);
237361

238362
// Use the request object to execute the function
239363
Xrm.WebApi.online.execute(createRequest).then(
240-
function (result) {
364+
function(result) {
241365
if (result.ok) {
242366
console.log("Status: %s %s", result.status, result.statusText);
243367
// perform other operations as required;
244368
}
245369
},
246-
function (error) {
370+
function(error) {
247371
console.log(error.message);
248372
// handle error conditions
249373
}
@@ -252,21 +376,20 @@ Xrm.WebApi.online.execute(createRequest).then(
252376

253377
#### Retrieve a record
254378

255-
The following example demonstrates how to perform a Retrieve operation.
379+
The following example demonstrates how to perform a retrieve operation.
256380

257381
```JavaScript
258382
var Sdk = window.Sdk || {};
259383

260384
/**
261385
* Request to execute a retrieve operation
262386
*/
263-
Sdk.RetrieveRequest = function (entityReference, columns) {
387+
Sdk.RetrieveRequest = function(entityReference, columns) {
264388
this.entityReference = entityReference;
265389
this.columns = columns;
266390
};
267-
268391
// NOTE: The getMetadata property should be attached to the function prototype instead of the
269-
// function object itself.
392+
// function object itself.
270393
Sdk.RetrieveRequest.prototype.getMetadata = function () {
271394
return {
272395
boundParameter: null,
@@ -285,27 +408,26 @@ var retrieveRequest = new Sdk.RetrieveRequest(entityReference, ["name"]);
285408

286409
// Use the request object to execute the function
287410
Xrm.WebApi.online.execute(retrieveRequest).then(
288-
function (result) {
411+
function(result) {
289412
if (result.ok) {
290413
console.log("Status: %s %s", result.status, result.statusText);
291414
result.json().then(
292-
function (response) {
415+
function(response) {
293416
console.log("Name: %s", response.name);
294417
// perform other operations as required;
295418
});
296419
}
297420
},
298-
function (error) {
421+
function(error) {
299422
console.log(error.message);
300423
// handle error conditions
301424
}
302425
);
303-
304426
```
305427

306428
#### Update a record
307429

308-
The following example demonstrates how to perform a Update operation.
430+
The following example demonstrates how to perform a update operation.
309431

310432
```JavaScript
311433
var Sdk = window.Sdk || {};
@@ -314,14 +436,14 @@ var Sdk = window.Sdk || {};
314436
/**
315437
* Request to execute an update operation
316438
*/
317-
Sdk.UpdateRequest = function (entityName, entityId, payload) {
439+
Sdk.UpdateRequest = function(entityName, entityId, payload) {
318440
this.etn = entityName;
319441
this.id = entityId;
320442
this.payload = payload;
321443
};
322444

323445
// NOTE: The getMetadata property should be attached to the function prototype instead of the
324-
// function object itself.
446+
// function object itself.
325447
Sdk.UpdateRequest.prototype.getMetadata = function () {
326448
return {
327449
boundParameter: null,
@@ -339,13 +461,13 @@ var updateRequest = new Sdk.UpdateRequest("account", "d2b6c3f8-b0fa-e911-a812-00
339461

340462
// Use the request object to execute the function
341463
Xrm.WebApi.online.execute(updateRequest).then(
342-
function (result) {
464+
function(result) {
343465
if (result.ok) {
344466
console.log("Status: %s %s", result.status, result.statusText);
345467
// perform other operations as required;
346468
}
347469
},
348-
function (error) {
470+
function(error) {
349471
console.log(error.message);
350472
// handle error conditions
351473
}
@@ -354,20 +476,20 @@ Xrm.WebApi.online.execute(updateRequest).then(
354476

355477
#### Delete a record
356478

357-
The following example demonstrates how to perform a Delete operation.
479+
The following example demonstrates how to perform a delete operation.
358480

359481
```JavaScript
360482
var Sdk = window.Sdk || {};
361483

362484
/**
363485
* Request to execute a delete operation
364486
*/
365-
Sdk.DeleteRequest = function (entityReference) {
487+
Sdk.DeleteRequest = function(entityReference) {
366488
this.entityReference = entityReference;
367489
};
368490

369491
// NOTE: The getMetadata property should be attached to the function prototype instead of the
370-
// function object itself.
492+
// function object itself.
371493
Sdk.DeleteRequest.prototype.getMetadata = function () {
372494
return {
373495
boundParameter: null,
@@ -377,6 +499,7 @@ Sdk.DeleteRequest.prototype.getMetadata = function () {
377499
};
378500
};
379501
};
502+
};
380503

381504
// Construct request object from the metadata
382505
var entityReference = {
@@ -387,13 +510,13 @@ var deleteRequest = new Sdk.DeleteRequest(entityReference);
387510

388511
// Use the request object to execute the function
389512
Xrm.WebApi.online.execute(deleteRequest).then(
390-
function (result) {
513+
function(result) {
391514
if (result.ok) {
392515
console.log("Status: %s %s", result.status, result.statusText);
393516
// perform other operations as required;
394517
}
395518
},
396-
function (error) {
519+
function(error) {
397520
console.log(error.message);
398521
// handle error conditions
399522
}

powerapps-docs/maker/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,6 +1804,8 @@
18041804
href: ./canvas-apps/get-sessionid.md
18051805
- name: Troubleshoot startup issues for Power Apps
18061806
href: troubleshooting-startup-issues.md
1807+
- name: Troubleshoot sign-in issues for Power Apps mobile
1808+
href: ../user/powerapps_mobile_troubleshoot.md
18071809
- name: Troubleshoot Power Query
18081810
href: ./common-data-service/data-platform-cds-newentity-troubleshooting-mashup.md
18091811
- name: Support

0 commit comments

Comments
 (0)