Skip to content

Client API updates #9709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: development
Choose a base branch
from

Conversation

exec-astraea
Copy link
Contributor

@exec-astraea exec-astraea commented Jun 19, 2025

In Mendix 10.22 we introduced the new Client API. It uses promises and works as a modern JS module instead of being attached to the global window object.

This PR removes all mentions of the old mx. and logger APIs for Mendix 10 and 11. JS actions guide was also partially rewritten using new APIs.

Note that docs still mention mx.session.getConfig("csrftoken") in Mendix 10 guide. getCSRFToken was introduced quite late (Mendix 10.23). Plus, at the moment there is no way to import the new API in pluggable widgets.
We'll revise these docs after 10.6, 10.12 and 10.18 are out of support and after getCSRFToken is availaible in Pluggable Widgets.

@exec-astraea
Copy link
Contributor Author

Mendix 11 guide for Session Management already mentions the new login method. I decided not to touch Mendix 10 version for now. The guide is complicated enough as it is and adding blocks like "if you're below 10.22 use X otherwise Y" would make it worse 😄
We'll update the guide after MTS versions are out of support.

const mxObject = await create({ entity: "HowTo.GitHubUser" });
// Dynamically set attributes
mxObject.getAttributes()
.forEach(function(attributeName) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can just use arrow functions as well in the examples?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

const mxObject = await create({ entity: userEntity });
// Dynamically set attributes
mxObject.getAttributes()
.forEach(function(attributeName) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can just use arrow functions as well in the examples?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

Copy link
Collaborator

@MarkvanMents MarkvanMents left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a couple of comments about the things which have been taken out of the Mendix 10 version of the document and how that affects customers who are still on earlier versions of Mendix (10.12 or 10.18).
Can you have a look and see if we need to keep some of that documentation to support customers who cannot upgrade quickly.

@@ -290,36 +289,6 @@ Use the following code to employ an asynchronous return for when your nanoflow n

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.

#### Understanding Promises

A `Promise` object represents the eventual completion (or failure) of an asynchronous operation and its resulting value.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see there are lots of mentions of Promise still in this document. Do we still need this explanation of what a Promise is, even if you don't need to use it on callback APIs?

I see the next section is also about Promises,

* 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)
* The resolve will return a Boolean value, which is used as the return value of the action
* In the nanoflow, the return variable can be used for an alternative flow for confirmation and cancel

#### Understanding Promise API
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading the section below this, I'm not sure why it is titled "Promise API" but the whole text is about "Fetch API"?

Comment on lines -293 to -316
#### Understanding Promises

A `Promise` object represents the eventual completion (or failure) of an asynchronous operation and its resulting value.

Use the following code to wrap a callback API in a promise:

```javascript
function AskConfirmation(question) {
// BEGIN USER CODE
return new Promise(function (resolve) {
mx.ui.confirmation({
content: question,
handler: function() {
resolve(true);
},
onCancel: function() {
resolve(false);
}
});
});
// END USER CODE
}
```

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is still needed for customers who are using an MTS version of Mendix 10?

Comment on lines +186 to +196
import { create } from "mx-api/data"

try {
const cat = await create({ entity: "MyFirstModule.Cat" })
console.log("Object created on server:", cat);
} catch (err) {
console.error("Could not commit object:", err);
}
```

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*.
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*.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to keep the old information as well for those who are still using MTS versions of Mendix 10.

Comment on lines +121 to +129
async function createGitHubUser(user) {
try {
const mxObject = await create({ entity: "HowTo.GitHubUser" });
mxObject.set("login", user.login);
mxObject.set("avatar_url", user.avatar_url);
return mxObject;
} catch(err) {
throw new Error("Could not create object:" + err.message)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this work in MTS versions of Mendix 10 (e.g. 10.18)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants