Skip to content

Commit 3a3598d

Browse files
committed
Clarify which code to use in Mx10.22 and below
1 parent c41eab4 commit 3a3598d

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

content/en/docs/howto/extensibility/best-practices-javascript-actions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ Use the following code to employ an asynchronous return for when your nanoflow n
287287
}
288288
```
289289

290-
Many APIs and functions are designed in an asynchronous way, and use callback functions or promises. A JavaScript action expects a promise to be returned. The promise should be resolved with the return value as expected in the action.
290+
Many APIs and functions are designed in an asynchronous way, and use callback functions or [promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). A JavaScript action expects a promise to be returned. The promise should be resolved with the return value as expected in the action.
291291

292292
#### Understanding Promise API
293293

content/en/docs/howto10/extensibility/best-practices-javascript-actions.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ For information on how to use *Big.js*, consult the [big.js API](https://mikemcl
180180

181181
#### Creating Objects
182182

183-
Use the following code to create objects:
183+
Use the following code to create objects in Mendix version 10.23 and above:
184184

185185
```javascript
186186
import { create } from "mx-api/data"
@@ -195,6 +195,8 @@ try {
195195

196196
For more information on creating objects, consult the [Create](https://apidocs.rnd.mendix.com/10/client-mx-api/module-mx-api_data.html#.create) section of the *Mendix Client API*.
197197

198+
If you are using Mendix version 10.22 or below, you will need to use [`mx.data.create`](https://apidocs.rnd.mendix.com/10/client/mx.data.html#.create).
199+
198200
#### Changing Objects
199201

200202
Use the following code to change objects:
@@ -295,6 +297,30 @@ Explaining the callback code:
295297
* The resolve will return a Boolean value, which is used as the return value of the action
296298
* In the nanoflow, the return variable can be used for an alternative flow for confirmation and cancel
297299

300+
#### Understanding Promises
301+
302+
If you are using Mendix version 10.23 or below, you will need to use promises. A `Promise` object represents the eventual completion (or failure) of an asynchronous operation and its resulting value.
303+
304+
Use the following code in Mendix versions 10.23 or below to wrap a callback API in a promise:
305+
306+
```javascript
307+
function AskConfirmation(question) {
308+
// BEGIN USER CODE
309+
return new Promise(function (resolve) {
310+
mx.ui.confirmation({
311+
content: question,
312+
handler: function() {
313+
resolve(true);
314+
},
315+
onCancel: function() {
316+
resolve(false);
317+
}
318+
});
319+
});
320+
// END USER CODE
321+
}
322+
```
323+
298324
#### Understanding Promise API
299325

300326
This function uses the Fetch API:

content/en/docs/howto10/extensibility/build-javascript-actions/write-javascript-github.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ description: "This advanced how-to teaches you to make a JavaScript action which
1010

1111
Nanoflows are even more powerful with pluggable nanoflow actions — called JavaScript actions. [How to Build JavaScript Actions: Part 1 (Basic)](/howto10/extensibility/write-javascript-actions/) shows you how to create a JavaScript TextToSpeech action, expose it as a nanoflow action, and then use it in a demo. In this advanced how-to you will learn to call a REST service, use a generic return type, and make an API to enhance the power of your JavaScript actions.
1212

13+
{{% alert color="warning" %}}
14+
The code on this page assumes you are using Mendix version 10.23.0 or above, the LTS version of Mendix 10. If you are using a previous version, you can refer to the code in the Mendix 9 version of [Build JavaScript Actions: Part 2 (Advanced)](/howto9/extensibility/write-javascript-github/).
15+
{{% /alert %}}
16+
1317
This how-to teaches you how to do the following:
1418

1519
* Create a JavaScript action

0 commit comments

Comments
 (0)