You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For more information on creating objects, consult the [Create](https://apidocs.rnd.mendix.com/10/client/mx.data.html#.create) section of the *Mendix Client API*.
196
+
For more information on creating objects, consult the [Create](https://apidocs.rnd.mendix.com/11/client-mx-api/module-mx-api_data.html#.create) section of the *Mendix Client API*.
198
197
199
198
#### Changing Objects
200
199
@@ -288,37 +287,7 @@ Use the following code to employ an asynchronous return for when your nanoflow n
288
287
}
289
288
```
290
289
291
-
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.
292
-
293
-
#### Understanding Promises
294
-
295
-
A `Promise` object represents the eventual completion (or failure) of an asynchronous operation and its resulting value.
296
-
297
-
Use the following code to wrap a callback API in a promise:
298
-
299
-
```javascript
300
-
functionAskConfirmation(question) {
301
-
// BEGIN USER CODE
302
-
returnnewPromise(function (resolve) {
303
-
mx.ui.confirmation({
304
-
content: question,
305
-
handler:function() {
306
-
resolve(true);
307
-
},
308
-
onCancel:function() {
309
-
resolve(false);
310
-
}
311
-
});
312
-
});
313
-
// END USER CODE
314
-
}
315
-
```
316
-
317
-
Explaining the callback code:
318
-
319
-
* Use the standard Mendix Client to show a confirmation dialog box with an **OK** and a **Cancel** button (the execution of the nanoflow halts until the user clicks one of the buttons)
320
-
* The resolve will return a Boolean value, which is used as the return value of the action
321
-
* In the nanoflow, the return variable can be used for an alternative flow for confirmation and cancel
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.
thrownewError("Could not create object:"+err.message)
129
+
}
133
130
}
134
131
// END USER CODE
135
132
}
@@ -140,6 +137,8 @@ To create a JavaScript action that can search for users on GitHub, follow the st
140
137
11. The function will only set the `login` and `avatar_url` properties. To make it more flexible, you will make the function discover the available attributes and set them. Extend the domain model with more attributes from the API like so:
141
138
142
139
```javascript
140
+
import { create } from "mx-api/data"
141
+
143
142
export asyncfunctionSearchGitHubUsers(query) {
144
143
// BEGIN USER CODE
145
144
if (!query) {
@@ -148,30 +147,25 @@ To create a JavaScript action that can search for users on GitHub, follow the st
thrownewError("Could not create object:"+err.message)
168
+
}
175
169
}
176
170
// END USER CODE
177
171
}
@@ -196,9 +190,11 @@ To create a JavaScript action that can search for users on GitHub, follow the st
196
190
197
191
{{< figure src="/attachments/howto/extensibility/build-javascript-actions/write-javascript-github/select-user-entity.png" alt="select user entity"class="no-border">}}
198
192
199
-
15. Your final step is updating the code. Thenew`userEntity` parameter has already been added. In the `mx.data.create`function, set `userEntity` as the `entity` to be created. Then, add some documentation for future reference:
193
+
15. Your final step is updating the code. Thenew`userEntity` parameter has already been added. In the `create`function, set `userEntity` as the `entity` to be created. Then, add some documentation for future reference:
200
194
201
195
```javascript
196
+
import { create } from "mx-api/data"
197
+
202
198
/*
203
199
Searching users on GitHub.com, it could find users via various criteria. This action returns up to 100 results.
204
200
@param {string} query - The query contains one or more search keywords and qualifiers. Qualifiers allow you to limit your search to specific areas of GitHub.
@@ -225,31 +221,24 @@ To create a JavaScript action that can search for users on GitHub, follow the st
Copy file name to clipboardExpand all lines: content/en/docs/howto/security/best-practices-security.md
+7-1Lines changed: 7 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -139,7 +139,13 @@ This authentication option is not available for Published Web Services and can o
139
139
140
140
If you choose this option, the API will expect a "X-Csrf-Token" HTTP request header to be set on each incoming request. This authentication option is particularly interesting for custom JavaScript and widget implementations.
141
141
142
-
The session token can be acquired by calling `mx.session.getConfig("csrftoken")` in JavaScript. This method call should be used before each API call to prevent cross-site request forgery (CSRF/XSRF).
142
+
The session token can be acquired by calling a Mendix Client API method to get the current CSRF token. This method should be called before each API call in your widget or JavaScript action to prevent cross-site request forgery (CSRF/XSRF).
For more information on creating objects, consult the [Create](https://apidocs.rnd.mendix.com/10/client/mx.data.html#.create) section of the *Mendix Client API*.
196
+
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*.
197
+
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).
198
199
199
200
#### Changing Objects
200
201
@@ -290,11 +291,17 @@ Use the following code to employ an asynchronous return for when your nanoflow n
290
291
291
292
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.
292
293
294
+
Explaining the callback code:
295
+
296
+
* Use the standard Mendix Client to show a confirmation dialog box with an **OK** and a **Cancel** button (the execution of the nanoflow halts until the user clicks one of the buttons)
297
+
* The resolve will return a Boolean value, which is used as the return value of the action
298
+
* In the nanoflow, the return variable can be used for an alternative flow for confirmation and cancel
299
+
293
300
#### Understanding Promises
294
301
295
-
A `Promise` object represents the eventual completion (or failure) of an asynchronous operation and its resulting value.
302
+
If you are using Mendix version 10.22 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.
296
303
297
-
Use the following code to wrap a callback API in a promise:
304
+
Use the following code in Mendix versions 10.23 or below to wrap a callback API in a promise:
298
305
299
306
```javascript
300
307
functionAskConfirmation(question) {
@@ -314,12 +321,6 @@ function AskConfirmation(question) {
314
321
}
315
322
```
316
323
317
-
Explaining the callback code:
318
-
319
-
* Use the standard Mendix Client to show a confirmation dialog box with an **OK** and a **Cancel** button (the execution of the nanoflow halts until the user clicks one of the buttons)
320
-
* The resolve will return a Boolean value, which is used as the return value of the action
321
-
* In the nanoflow, the return variable can be used for an alternative flow for confirmation and cancel
0 commit comments