### File Name Example (JavaScript) Source: https://apidocs.rnd.mendix.com/11/client-mx-api/FileOptions Provides an example of setting the 'name' property for FileOptions, specifying the desired filename for a saved file. This is a string value. ```javascript "report.pdf" ``` -------------------------------- ### Image Height Example (JavaScript) Source: https://apidocs.rnd.mendix.com/11/client-mx-api/FileOptions Shows an example of setting the 'height' property for FileOptions, specifying the desired height in pixels for image files. This is a numerical value. ```javascript 600 ``` -------------------------------- ### Sort Specification Example - JavaScript Source: https://apidocs.rnd.mendix.com/11/client-mx-api/Filter Illustrates how to define sorting criteria within a Filter object. This example shows sorting by the 'Name' attribute in ascending order. ```javascript // Sort by "Name" in ascending order [["Name", "asc"]]; ``` -------------------------------- ### Image Width Example (JavaScript) Source: https://apidocs.rnd.mendix.com/11/client-mx-api/FileOptions Illustrates setting the 'width' property for FileOptions, defining the desired width in pixels for image files. This is a numerical value. ```javascript 800 ``` -------------------------------- ### Trigger Object Subscriptions using Mendix API Source: https://apidocs.rnd.mendix.com/11/client-mx-api/module-mx-api_data This example demonstrates how to trigger object subscriptions using the Mendix Client API's `update` function. It requires the `guid` of the `MxObject` to specify which object's updates to subscribe to. This is a common pattern for real-time data synchronization. ```javascript await update({ guid: "123213" }); ``` -------------------------------- ### MxObject - getGuid Source: https://apidocs.rnd.mendix.com/11/client-mx-api/MxObject Returns the GUID of the MxObject. ```APIDOC ## GET /api/mxobject/getGuid ### Description Returns the Globally Unique Identifier (GUID) of this MxObject. ### Method GET ### Endpoint `/api/mxobject/getGuid` ### Response #### Success Response (200) - **GUID** (string) - The GUID of the MxObject. ### Request Example ```javascript mxobj.getGuid(); ``` ### Response Example ```json "1234567890131" ``` ``` -------------------------------- ### Trigger Attribute Subscriptions using Mendix API Source: https://apidocs.rnd.mendix.com/11/client-mx-api/module-mx-api_data This example shows how to trigger attribute-specific subscriptions using the Mendix Client API's `update` function. It requires both the `guid` of the `MxObject` and the `attr` name to target updates for a particular attribute. This allows for more granular data monitoring. ```javascript await update({ guid: "123213", attr: "Name" }); ``` -------------------------------- ### Create Equality FunctionQueryFilter Source: https://apidocs.rnd.mendix.com/11/client-mx-api/FunctionQueryFilter This example demonstrates how to create a FunctionQueryFilter for an equality check. It compares a literal value 'John' with the 'Name' attribute. ```javascript const filter = { type: "function", name: "=", parameters: [ { type: "value", value: "John", isGuid: false }, { type: "attribute", attribute: "Name", attributeType: "String" } ] }; ``` -------------------------------- ### Fetch Data from MxObject Path (JavaScript) Source: https://apidocs.rnd.mendix.com/11/client-mx-api/MxObject Retrieves data (attribute value, object GUID, or array of GUIDs) from an MxObject by traversing a specified path. It utilizes a callback function to handle the fetched data or an error callback for issues. This is a callback-based alternative to mx.data.get. ```javascript mxobj.fetch("Name", function(value) { alert("Person's name is " + value); }); ``` ```javascript mxobj.fetch("MyFirstModule.Friend/MyFirstModule.Person", function(value) { alert("Name of person's friend is " + value.get("Name")); }); ``` ```javascript mxobj.fetch("MyFirstModule.Owns/MyFirstModule.Pet", function(value) { alert("Person owns the following pets: " + value); }); ``` ```javascript mxobj.fetch("MyFirstModule.Friend/MyFirstModule.Person/" + "MyFirstModule.Father/MyFirstModule.Person/" + "Age", function(value) { alert("Name of the father of this person's friend is " + value); }); ``` -------------------------------- ### Get Original References (MxObject) Source: https://apidocs.rnd.mendix.com/11/client-mx-api/MxObject Retrieves the original GUIDs of objects referenced by a reference or reference set attribute. This is useful for comparing current references with those at the last commit. It takes the attribute name as input and returns an array of GUID strings. ```javascript mxobj.getOriginalReferences("MyFirstModule.Ref"); // Returns [ "12345", "12346" ] ``` -------------------------------- ### GetPets JavaScript Action Source: https://apidocs.rnd.mendix.com/11/client-mx-api/index Example JavaScript action to retrieve all pets from the database, create a new pet if none exist, and display a confirmation dialog. ```APIDOC ## GetPets JavaScript Action ### Description This JavaScript action retrieves all entities of type 'MyFirstModule.Pet'. If no pets are found, it creates a new pet named 'Buddy' with age 3, commits it to the database, and then retrieves the pets again. Finally, it displays a dialog indicating the user who retrieved the pets. ### Method N/A (JavaScript Action) ### Endpoint N/A ### Parameters N/A ### Request Example ```javascript // This file was generated by Mendix Studio Pro. // // WARNING: Only the following code will be retained when actions are regenerated: // - the import list // - the code between BEGIN USER CODE and END USER CODE // - the code between BEGIN EXTRA CODE and END EXTRA CODE // Other code you write will be lost the next time you deploy the project. import "mx-global"; import { Big } from "big.js"; import { create, commit, retrieveByEntity } from "mx-api/data"; import { getUserName } from "mx-api/session"; import { showDialog } from "mx-api/ui"; // BEGIN EXTRA CODE // END EXTRA CODE /** * @returns {Promise.} */ export async function GetPets() { // BEGIN USER CODE try { // Retrieve all pets let pets = await retrieveByEntity({ entity: "MyFirstModule.Pet" }); // If no pets are found, create a new pet if (pets.length === 0) { const newPet = await create({ entity: "MyFirstModule.Pet" }); newPet.set("Name", "Buddy"); newPet.set("Age", 3); await commit({ objects: [newPet] }); // Retrieve pets again after creating a new one pets = await retrieveByEntity({ entity: "MyFirstModule.Pet" }); } // Show a dialog with the current user's name const userName = getUserName(); showDialog({ type: "info", content: `Pets retrieved by ${userName}` }); return pets; } catch (error) { showDialog({ type: "error", content: `Something went wrong: ${error.message}` }); } // END USER CODE } ``` ### Response #### Success Response (200) - **pets** (Array) - An array of pet objects retrieved from the database. #### Response Example ```json [ { "__uuid__": "some-uuid-1", "Name": "Buddy", "Age": 3 } ] ``` ``` -------------------------------- ### Get Referenced Objects GUIDs (MxObject) Source: https://apidocs.rnd.mendix.com/11/client-mx-api/MxObject Retrieves the GUIDs of objects referenced by a reference or reference set attribute. This method takes the attribute name as input and returns an array of GUID strings. ```javascript mxobj.getReferences("MyFirstModule.Ref"); // Returns [ "12345", "12346" ] ``` -------------------------------- ### UserLoginAndLogout JavaScript Action Source: https://apidocs.rnd.mendix.com/11/client-mx-api/index Example JavaScript action to log in a user, display their roles, and prompt for confirmation before logging them out. ```APIDOC ## UserLoginAndLogout JavaScript Action ### Description This JavaScript action handles user authentication. It logs in a user with provided credentials, retrieves their role names, and then presents a confirmation dialog before proceeding with the logout process. If logout is cancelled, a message is displayed. ### Method N/A (JavaScript Action) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```javascript // This file was generated by Mendix Studio Pro. // // WARNING: Only the following code will be retained when actions are regenerated: // - the import list // - the code between BEGIN USER CODE and END USER CODE // - the code between BEGIN EXTRA CODE and END EXTRA CODE // Other code you write will be lost the next time you deploy the project. import "mx-global"; import { Big } from "big.js"; import { login, logout } from "mx-api"; import { getUserRoleNames } from "mx-api/session"; import { confirmation, showDialog } from "mx-api/ui"; // BEGIN EXTRA CODE // END EXTRA CODE /** * @param {string} username * @param {string} password * @returns {Promise.} */ export async function UserLoginAndLogout(username, password) { // BEGIN USER CODE try { // Log in the user await login({ username, password, useAuthToken: true, reloadOnSuccess: false }); // Retrieve the user's roles const roles = getUserRoleNames(); // Show a confirmation dialog with the user's roles await confirmation({ content: `User roles: ${roles.join(", ")}` }); // Show a confirmation dialog before logging out const confirmed = await confirmation({ content: "Do you really want to log out?", okText: "Yes, I want to log out", cancelText: "No, stay logged in", }); if (confirmed) { // Log out the user await logout(); } else { showDialog({ type: "info", content: "Logout cancelled." }); } } catch (error) { showDialog({ type: "error", content: `Something went wrong: ${error.message}` }); } // END USER CODE } ``` ### Response N/A (This action performs operations and shows UI feedback, but does not return a specific data payload). ### Response Example N/A ``` -------------------------------- ### GET /api/appurl Source: https://apidocs.rnd.mendix.com/11/client-mx-api/module-mx-api Retrieves the root URL of the Mendix application. ```APIDOC ## GET /api/appurl ### Description Retrieves the root URL from which the Mendix application is loaded. This URL typically includes the domain and application path, e.g., `https://domain.com/mendixapp/`. ### Method GET ### Endpoint `/api/appurl` ### Parameters None ### Request Example None ### Response #### Success Response (200) - **appUrl** (string) - The root URL of the application. #### Response Example ```json { "appUrl": "https://your-app.mendixcloud.com/mendixapp/" } ``` ``` -------------------------------- ### Get GUID (MxObject) Source: https://apidocs.rnd.mendix.com/11/client-mx-api/MxObject Returns the unique identifier (GUID) of the MxObject. This GUID is a string that uniquely identifies the object within the Mendix application. ```javascript mxobj.getGuid(); // Returns "1234567890131" ``` -------------------------------- ### Get User ID - JavaScript Source: https://apidocs.rnd.mendix.com/11/client-mx-api/module-mx-api_session Fetches the unique identifier (GUID) of the currently logged-in user. This method is useful for referencing user-specific data or performing user-based operations. The GUID is returned as a string. ```javascript mx.session.getUserId(); // "2533274790395905" ``` -------------------------------- ### Retrieve and Check Object Changes (JavaScript) Source: https://apidocs.rnd.mendix.com/11/client-mx-api/MxObject Demonstrates how to retrieve an object by its GUID and check if it has unsaved changes using `mx.data.get` or `retrieveByGuids`. It shows how to modify an attribute and re-check for changes. ```javascript mx.data.get({ guid: "12345", callback: function(obj) { // Object is fresh from the runtime; next line prints 'false'. console.log(obj.hasChanges()); obj.set("Name", "foo"); // Object has a changed attribute; next line prints 'true'. console.log(obj.hasChanges()); } }); ``` ```javascript const objects = await retrieveByGuids({ guids: ["12345"] }); const obj = objects[0]; // Object is fresh from the runtime; next line prints 'false'. console.log(obj.hasChanges()); obj.set("Name", "foo"); // Object has a changed attribute; next line prints 'true'. console.log(obj.hasChanges()); ``` -------------------------------- ### Get Single Referenced Object GUID (MxObject) Source: https://apidocs.rnd.mendix.com/11/client-mx-api/MxObject Retrieves the GUID of the single object referenced by a reference attribute. This method will throw an exception if used on a non-reference attribute or a reference set attribute. It takes the attribute name as input and returns a GUID string. ```javascript mxobj.getReference("MyFirstModule.Ref"); // Returns "12345" ``` -------------------------------- ### MxObject - getReferences Source: https://apidocs.rnd.mendix.com/11/client-mx-api/MxObject Retrieves the GUIDs of MxObjects referenced by a reference or reference set attribute. ```APIDOC ## GET /api/mxobject/getReferences ### Description Retrieves the GUIDs of objects referenced by a reference attribute or a reference set attribute. This method can return multiple GUIDs if the attribute is a reference set. ### Method GET ### Endpoint `/api/mxobject/getReferences` ### Parameters #### Query Parameters - **attr** (string) - Required - The reference or reference set attribute whose referenced objects to return. ### Response #### Success Response (200) - **GUIDs** (Array.) - An array of GUIDs representing the referenced objects. ### Request Example ```javascript mxobj.getReferences("MyFirstModule.Ref"); ``` ### Response Example ```json [ "12345", "12346" ] ``` ``` -------------------------------- ### Retrieve and Create Mendix Pets Source: https://apidocs.rnd.mendix.com/11/client-mx-api/index A JavaScript action example demonstrating how to retrieve all 'Pet' objects from the database using 'mx-api/data'. If no pets are found, it creates a new pet, commits it, and then retrieves the list again. It also shows a user's name and displays a dialog. ```javascript // This file was generated by Mendix Studio Pro. // // WARNING: Only the following code will be retained when actions are regenerated: // - the import list // - the code between BEGIN USER CODE and END USER CODE // - the code between BEGIN EXTRA CODE and END EXTRA CODE // Other code you write will be lost the next time you deploy the project. import "mx-global"; import { Big } from "big.js"; import { create, commit, retrieveByEntity } from "mx-api/data"; import { getUserName } from "mx-api/session"; import { showDialog } from "mx-api/ui"; // BEGIN EXTRA CODE // END EXTRA CODE /** * @returns {Promise.} */ export async function GetPets() { // BEGIN USER CODE try { // Retrieve all pets let pets = await retrieveByEntity({ entity: "MyFirstModule.Pet" }); // If no pets are found, create a new pet if (pets.length === 0) { const newPet = await create({ entity: "MyFirstModule.Pet" }); newPet.set("Name", "Buddy"); newPet.set("Age", 3); await commit({ objects: [newPet] }); // Retrieve pets again after creating a new one pets = await retrieveByEntity({ entity: "MyFirstModule.Pet" }); } // Show a dialog with the current user's name const userName = getUserName(); showDialog({ type: "info", content: `Pets retrieved by ${userName}` }); return pets; } catch (error) { showDialog({ type: "error", content: `Something went wrong: ${error.message}` }); } // END USER CODE } ``` -------------------------------- ### Retrieve Mendix Objects by Path Source: https://apidocs.rnd.mendix.com/11/client-mx-api/module-mx-api_data Retrieves Mendix Objects by traversing an association path from a starting object identified by its GUID. This method is available for both online and offline applications. The `entity` parameter specifies the target entity, and `direction` can be used for reverse associations. ```javascript const parent = await retrieveByPath({path: "MyFirstModule.Parent_Child", guid: "123456", entity: "MyFirstModule.Parent"}) ``` -------------------------------- ### Filter Object Example - JavaScript Source: https://apidocs.rnd.mendix.com/11/client-mx-api/Filter Demonstrates the structure of a Filter object used for querying data. It includes properties for limiting the number of results (amount), skipping records (offset), and specifying sorting order. ```javascript const filter = { amount: 50, offset: 10, sort: [["Name", "asc"], ["Age", "desc"]] }; ``` -------------------------------- ### MxObject - getReference Source: https://apidocs.rnd.mendix.com/11/client-mx-api/MxObject Retrieves the GUID of the object referenced by a reference attribute. Throws an exception for non-reference or reference set attributes. ```APIDOC ## GET /api/mxobject/getReference ### Description Retrieves the GUID of the object referenced by a reference attribute. This method is specifically for single-object references. ### Method GET ### Endpoint `/api/mxobject/getReference` ### Parameters #### Query Parameters - **reference** (string) - Required - The reference attribute whose referenced object to return. ### Response #### Success Response (200) - **GUID** (GUID) - The GUID of the MxObject referenced by the given reference attribute. ### Request Example ```javascript mxobj.getReference("MyFirstModule.Ref"); ``` ### Response Example ```json "12345" ``` ``` -------------------------------- ### Get Sub Entities (MxObject) Source: https://apidocs.rnd.mendix.com/11/client-mx-api/MxObject A convenience function that returns a list of sub-entities for the MxObject's entity. This method delegates to MxMetaObject#getSubEntities. ```javascript mxobject.getSubEntities(); // Returns [ "MyModule.EntityA", "MyModule.EntityB" ] ``` -------------------------------- ### Create Combined FunctionQueryFilter with AND and Contains Source: https://apidocs.rnd.mendix.com/11/client-mx-api/FunctionQueryFilter This example shows how to construct a complex FunctionQueryFilter using logical AND and string 'contains' operations. It filters records where the 'Name' is 'John' AND the 'Employer' contains 'Mendix'. ```javascript const filter = { type: "function", name: "and", parameters: [ { type: "function", name: "=", parameters: [ { type: "attribute", attribute: "Name", attributeType: "String" }, { type: "value", value: "John" } ] }, { type: "function", name: "contains", parameters: [ { type: "attribute", attribute: "Employer", attributeType: "String" }, { type: "value", value: "Mendix" } ] } ] }; ``` -------------------------------- ### MxObject - getEntity Source: https://apidocs.rnd.mendix.com/11/client-mx-api/MxObject Gets the entity name of the MxObject. ```APIDOC ## GET /api/mxobject/getEntity ### Description Gets the entity name of the MxObject. ### Method GET ### Endpoint `/api/mxobject/getEntity` ### Response #### Success Response (200) - **EntityName** (string) - The name of the entity. ### Request Example ```javascript mxobject.getEntity(); ``` ### Response Example ```json "System.User" ``` ``` -------------------------------- ### Get Super Entities (MxObject) Source: https://apidocs.rnd.mendix.com/11/client-mx-api/MxObject A convenience function that returns a list of super-entities for the MxObject's entity. This method delegates to MxMetaObject#getSuperEntities. ```javascript mxobject.getSuperEntities(); // Returns [ "MyModule.EntityC", "MyModule.EntityD", "System.User" ] ``` -------------------------------- ### Mendix User Login, Role Display, and Logout Source: https://apidocs.rnd.mendix.com/11/client-mx-api/index A JavaScript action example for handling user authentication. It logs in a user, retrieves their roles using 'mx-api/session', displays roles via a confirmation dialog, and prompts for logout confirmation before executing 'mx-api/logout'. ```javascript // This file was generated by Mendix Studio Pro. // // WARNING: Only the following code will be retained when actions are regenerated: // - the import list // - the code between BEGIN USER CODE and END USER CODE // - the code between BEGIN EXTRA CODE and END EXTRA CODE // Other code you write will be lost the next time you deploy the project. import "mx-global"; import { Big } from "big.js"; import { login, logout } from "mx-api"; import { getUserRoleNames } from "mx-api/session"; import { confirmation, showDialog } from "mx-api/ui"; // BEGIN EXTRA CODE // END EXTRA CODE /** * @param {string} username * @param {string} password * @returns {Promise.} */ export async function UserLoginAndLogout(username, password) { // BEGIN USER CODE try { // Log in the user await login({ username, password, useAuthToken: true, reloadOnSuccess: false }); // Retrieve the user's roles const roles = getUserRoleNames(); // Show a confirmation dialog with the user's roles await confirmation({ content: `User roles: ${roles.join(", ")}` }); // Show a confirmation dialog before logging out const confirmed = await confirmation({ content: "Do you really want to log out?", okText: "Yes, I want to log out", cancelText: "No, stay logged in", }); if (confirmed) { // Log out the user await logout(); } else { showDialog({ type: "info", content: "Logout cancelled." }); } } catch (error) { showDialog({ type: "error", content: `Something went wrong: ${error.message}` }); } // END USER CODE } ``` -------------------------------- ### Retrieve Mendix Objects by GUIDs Source: https://apidocs.rnd.mendix.com/11/client-mx-api/module-mx-api_data Retrieves Mendix Objects using an array of their unique GUIDs. This method works both online (from the Runtime) and offline (from the local database). It returns a promise that resolves with an array of MxObject instances or rejects with an error. ```javascript // Retrieve MxObjects by GUIDs. const objects = await retrieveByGuids({ guids: ["123456", "111111"] }); ``` -------------------------------- ### Create ValueQueryFilter (JavaScript) Source: https://apidocs.rnd.mendix.com/11/client-mx-api/ValueQueryFilter Demonstrates how to create a ValueQueryFilter object in JavaScript. This filter is used to specify a string value as a query parameter. The 'isGuid' property can be optionally set to true if the value represents a GUID. ```javascript const filter = { type: "value", value: "John", }; ``` ```javascript const filter = { type: "value", value: "12345678", isGuid: true, }; ``` -------------------------------- ### Get Attributes List from MxObject (JavaScript) Source: https://apidocs.rnd.mendix.com/11/client-mx-api/MxObject A convenience function that returns a list of all attribute names for an MxObject. This method is analogous to MxMetaObject#getAttributes. ```javascript mxobject.getAttributes(); // ["Name", "Age"]; ``` -------------------------------- ### Trigger Entity Subscriptions using Mendix API Source: https://apidocs.rnd.mendix.com/11/client-mx-api/module-mx-api_data This example illustrates how to trigger entity-wide subscriptions using the Mendix Client API's `update` function. It requires the `entity` name to subscribe to changes across all objects of that entity type. This is useful for monitoring broad data model changes. ```javascript await update({ entity: "System.User" }); ``` -------------------------------- ### Get Reference Attributes (MxObject) Source: https://apidocs.rnd.mendix.com/11/client-mx-api/MxObject A convenience function that returns a list of reference attributes associated with the MxObject. This method delegates to MxMetaObject#getReferenceAttributes. ```javascript mxobject.getReferenceAttributes(); // Returns [ "Mod.Person_Parent", "Mod.Person_Company" ] ``` -------------------------------- ### Get Mendix Application URL Source: https://apidocs.rnd.mendix.com/11/client-mx-api/module-mx-api Retrieves the root URL from which the Mendix application is loaded. This is useful for constructing absolute URLs within the application. ```javascript getAppUrl(); ``` -------------------------------- ### Mendix Query Filter Example Source: https://apidocs.rnd.mendix.com/11/client-mx-api/global Demonstrates the structure of a complex query filter for retrieving records from the local database in offline Mendix applications. It showcases nested functions for logical operations like AND, OR, and NOT, along with attribute comparisons and value checks. ```javascript const complexFilter = { type: "function", name: "and", parameters: [ { type: "function", name: "=", parameters: [ { type: "attribute", attribute: "Name", attributeType: "String" }, { type: "value", value: "John" } ] }, { type: "function", name: "or", parameters: [ { type: "function", name: "contains", parameters: [ { type: "attribute", attribute: "Employer", attributeType: "String" }, { type: "value", value: "Mendix" } ] }, { type: "function", name: "not", parameters: [ { type: "function", name: "=", parameters: [ { type: "attribute", attribute: "Age", attributeType: "Integer" }, { type: "value", value: 30 } ] }, { type: "function", name: "and", parameters: [ { type: "function", name: "starts-with", parameters: [ { type: "attribute", attribute: "FirstName", attributeType: "String" }, { type: "value", value: "A" } ] }, { type: "function", name: "ends-with", parameters: [ { type: "attribute", attribute: "LastName", attributeType: "String" }, { type: "value", value: "son" } ] } ] } ] } ] } ] }; ``` -------------------------------- ### Get User Role Names - JavaScript Source: https://apidocs.rnd.mendix.com/11/client-mx-api/module-mx-api_session Obtains an array containing the names of all roles assigned to the current user. This information can be used for role-based access control or to tailor the user interface. The roles are returned as an array of strings. ```javascript mx.session.getUserRoleNames(); ``` -------------------------------- ### Get User Name - JavaScript Source: https://apidocs.rnd.mendix.com/11/client-mx-api/module-mx-api_session Retrieves the 'Name' attribute of the current user. This is typically the display name associated with the user account. The name is returned as a string. ```javascript mx.session.getUserName(); // "MxAdmin" ``` -------------------------------- ### Get Entity Name (MxObject) Source: https://apidocs.rnd.mendix.com/11/client-mx-api/MxObject Retrieves the entity name of the MxObject. This is a simple getter method that returns a string representing the entity type. ```javascript mxobject.getEntity(); // Returns "System.User" ``` -------------------------------- ### ValueQueryFilter Interface Source: https://apidocs.rnd.mendix.com/11/client-mx-api/ValueQueryFilter Defines the structure for a value used in query filters. It supports a standard value and an optional boolean to indicate if the value is a GUID. ```APIDOC ## ValueQueryFilter Interface ### Description A value to be used as a parameter in a query filter. This interface allows specifying a value and optionally indicating if it represents a GUID. ### Fields - **type** (string) - Required - The type of the filter value, expected to be 'value'. - **value** (string) - Required - The actual value to be used in the filter. - **isGuid** (boolean) - Optional - Indicates if the `value` field represents a GUID. Defaults to false. ``` -------------------------------- ### Get Sub-Entities of an Object (JavaScript) Source: https://apidocs.rnd.mendix.com/11/client-mx-api/MxObject Retrieves the names of sub-entities associated with a given Mendix object. This function is a convenience wrapper around MxMetaObject#hasSubEntities. ```javascript mxobject.getSubEntities(); // [ "MyModule.EntityA", "MyModule.EntityB" ] ``` -------------------------------- ### Get Referenced Objects (MxObject) Source: https://apidocs.rnd.mendix.com/11/client-mx-api/MxObject Retrieves MxObjects referenced by a reference attribute. This method relies on objects being retrieved together using mx.data.get with specific filter settings. It returns an empty array if references are not available or have been modified. An exception is thrown for non-reference attributes or multi-association references. ```javascript mxobject.getChildren("attributeName"); ``` -------------------------------- ### Get Selector Entity (MxObject) Source: https://apidocs.rnd.mendix.com/11/client-mx-api/MxObject A convenience function that returns the entity name used by a selector for a given attribute. This method delegates to MxMetaObject#getSelectorEntity. ```javascript mxobject.getSelectorEntity("Order_OrderLine"); // Returns "CRM.OrderLine" ``` -------------------------------- ### Get CSRF Token - JavaScript Source: https://apidocs.rnd.mendix.com/11/client-mx-api/module-mx-api_session Retrieves the Cross-Site Request Forgery (CSRF) token for the current session. This token is essential for securing web applications against CSRF attacks. It is returned as a string. ```javascript mx.session.getCSRFToken(); ``` -------------------------------- ### Construct RelatedEntityQueryFilter in JavaScript Source: https://apidocs.rnd.mendix.com/11/client-mx-api/RelatedEntityQueryFilter Example of creating a RelatedEntityQueryFilter object in JavaScript. This filter allows you to define conditions based on attributes of related entities, chaining multiple conditions using logical operators like 'and' and 'contains'. ```javascript const relatedEntityFilter = { type: "relatedEntity", left: { type: "attribute", attribute: "EmployeeName", attributeType: "String", }, rightEntity: "MyFirstModule.Employee_Department", rightEntityAlias: "Department", right: { type: "attribute", attribute: "DepartmentName", attributeType: "String", }, next: { type: "function", name: "and", parameters: [ { type: "function", name: "=", parameters: [ { type: "attribute", attribute: "EmployeeName", attributeType: "String" }, { type: "value", value: "John" } ] }, { type: "function", name: "contains", parameters: [ { type: "attribute", attribute: "Department.Name", attributeType: "String" }, { type: "value", value: "Engineering" } ] } ] } }; ``` -------------------------------- ### Remove MxObjects using Mendix Client API Source: https://apidocs.rnd.mendix.com/11/client-mx-api/module-mx-api_data Removes MxObjects from the system based on their GUIDs. This method returns a Promise that resolves upon successful removal or rejects with an error. It is restricted in strict mode. ```javascript // Removes MxObjects by their `GUIDs` await remove({guids: [ "123456", "45678" ]}); ``` -------------------------------- ### Get File URL using Mendix Client API Source: https://apidocs.rnd.mendix.com/11/client-mx-api/module-mx-api_data Retrieves the URL for the most recent version of a stored file associated with an MxObject. The URL can be used for downloading or displaying the file. Optional parameters include a custom fileName and a thumbnail flag. This method returns a Promise resolving with the file URL. ```javascript // Get URL for a file const url = await getFileUrl({ object: mxobj }); ``` ```javascript // Get URL for a file with a custom name const url = await getFileUrl({ object: mxobj, fileName: "report.pdf" }); ``` -------------------------------- ### Get Attribute Value from MxObject (JavaScript) Source: https://apidocs.rnd.mendix.com/11/client-mx-api/MxObject Retrieves the value of a specified attribute from an MxObject. The return type varies based on the attribute's data type (e.g., string, number, boolean, Big, array of strings). Empty values are returned as null. ```javascript mxobj.get("IsActive"); // true ``` ```javascript mxobj.get("Name"); // "John Doe" ``` ```javascript numericValue = mxobj.get("LoginCount"); numericValue instanceof Big // true numericValue.toString() // "315" ``` -------------------------------- ### Get Original Attribute Value (MxObject) Source: https://apidocs.rnd.mendix.com/11/client-mx-api/MxObject Returns the original, last committed value of a specified attribute. This method is useful for tracking changes or reverting to a previous state. The return type depends on the attribute's data type. ```javascript mxobj.getOriginalValue("Name"); // Returns "Fred" ``` -------------------------------- ### Mendix Client API Usage Source: https://apidocs.rnd.mendix.com/11/client-mx-api/index Demonstrates how to import and use methods from the Mendix client API, either directly or by importing submodules. ```APIDOC ## Mendix Client API Usage ### Description This section illustrates the two primary methods for integrating the Mendix client API into your JavaScript actions: direct import of functions or importing entire submodules. ### Method Importing modules and calling functions. ### Endpoint N/A (Client-side API) ### Parameters N/A ### Request Example ```javascript // Direct import import { login } from "mx-api"; import { commit } from "mx-api/data"; import { getUserId } from "mx-api/session"; import { showDialog } from "mx-api/ui"; await login({ username: "demo_user", password: "123456" }); await commit({ objects: [newUser] }); const userId = getUserId(); showDialog({ type: "info", content: `User created` }); // Importing submodules import { data, ui, session } from "mx-api"; await data.commit({ objects: [newUser] }); const userId = session.getUserId(); ui.showDialog({ type: "info", content: `User created` }); ``` ### Response N/A (Client-side API actions) ### Response Example N/A ``` -------------------------------- ### Import Mendix API Methods Directly Source: https://apidocs.rnd.mendix.com/11/client-mx-api/index Demonstrates how to import specific methods directly from the 'mx-api' module and its submodules for use in JavaScript actions. This approach allows for cleaner import statements when only a few API functions are needed. ```javascript import { login } from "mx-api"; import { commit } from "mx-api/data"; import { getUserId } from "mx-api/session"; import { showDialog } from "mx-api/ui"; await login({ username: "demo_user", password: "123456" }); await commit({ objects: [newUser] }); const userId = getUserId(); showDialog({ type: "info", content: `User created` }); ``` -------------------------------- ### FileOptions Object Structure (JavaScript) Source: https://apidocs.rnd.mendix.com/11/client-mx-api/FileOptions Demonstrates the structure of the FileOptions object, used to specify parameters for saving files. It includes properties like name, width, and height. ```javascript const fileOptions = { name: "image.png", width: 800, height: 600 }; ``` -------------------------------- ### FileOptions Source: https://apidocs.rnd.mendix.com/11/client-mx-api/FileOptions Represents options for saving files, including name, width, and height. ```APIDOC ## FileOptions ### Description Represents options for saving files. ### Parameters #### Request Body - **name** (string) - Optional - The name of the file to be saved. If not provided, it will be derived from the `blob` parameter. For ``File`` blobs (e.g. those retrieved from an ``) this is the name of the file, for ``Blob`` objects it is `blob`. - **width** (number) - Optional - The desired width in pixels for image files. - **height** (number) - Optional - The desired height in pixels for image files. ### Request Example ```json { "name": "image.png", "width": 800, "height": 600 } ``` ### Response #### Success Response (200) - **name** (string) - The name of the saved file. - **width** (number) - The width of the saved image file. - **height** (number) - The height of the saved image file. #### Response Example ```json { "name": "image.png", "width": 800, "height": 600 } ``` ``` -------------------------------- ### Import Mendix API Submodules Source: https://apidocs.rnd.mendix.com/11/client-mx-api/index Illustrates importing entire submodules of the 'mx-api' package and accessing their methods through the submodule object. This is useful when multiple functions from the same submodule are frequently used. ```javascript import { data, ui, session } from "mx-api"; await data.commit({ objects: [newUser] }); const userId = session.getUserId(); ui.showDialog({ type: "info", content: `User created` }); ``` -------------------------------- ### Remove References from an Attribute in JavaScript Source: https://apidocs.rnd.mendix.com/11/client-mx-api/MxObject This JavaScript function `removeReferences` is used to remove specific objects (identified by their GUIDs) from a reference attribute of a Mendix object. It returns a boolean indicating success or failure. Ensure the attribute name and GUIDs are correctly provided. ```javascript mxobj.removeReferences("MyFirstModule.Ent_RefEnt", ["12345", "12346"]); ``` -------------------------------- ### POST /api/login Source: https://apidocs.rnd.mendix.com/11/client-mx-api/module-mx-api Authenticates a user with provided credentials. ```APIDOC ## POST /api/login ### Description Attempts to log in a user using their username and password. Supports options for using authentication tokens and controlling page reloads upon successful login. ### Method POST ### Endpoint `/api/login` ### Parameters #### Request Body - **username** (string) - Required - The username for login. - **password** (string) - Required - The password for login. - **useAuthToken** (boolean) - Optional - If true, the user stays logged in until the token expires. If omitted, the default behavior of the requested profile is used. - **reloadOnSuccess** (boolean) - Optional - If true (default), the page reloads on successful login. If false, manual success handling is allowed. ### Request Example ```json { "username": "fred", "password": "fred's unguessable password", "useAuthToken": true, "reloadOnSuccess": false } ``` ### Response #### Success Response (200) Indicates a successful login. The response body may be empty or contain minimal confirmation. #### Response Example ```json { "status": "success" } ``` #### Error Response (401, 400, etc.) Indicates login failure due to invalid credentials or other issues. #### Error Response Example ```json { "error": "Invalid username or password." } ``` ``` -------------------------------- ### Module Exports Source: https://apidocs.rnd.mendix.com/11/client-mx-api/module-mx-api This section outlines the main modules exported by the mx-api library, providing access to data, parsing, session, and UI functionalities. ```APIDOC ## Module Exports ### Description Exports functionalities from sub-modules for data management, parsing, session handling, and UI interactions. ### Exports - **mx-api/data**: Provides data-related functionalities. - **mx-api/parser**: Offers parsing capabilities. - **mx-api/session**: Manages user sessions. - **mx-api/ui**: Contains UI interaction methods. ``` -------------------------------- ### Format Attribute Value to String - JavaScript Source: https://apidocs.rnd.mendix.com/11/client-mx-api/module-mx-api_parser Converts a given value to its string representation based on the specified attribute type and optional formatting configurations. Supports custom date patterns and numeric precision. ```javascript formatValue(Big(3000), "Decimal", { places: 2 }); // "3000.00" formatValue(+new Date(1980, 7, 23), "DateTime", { datePattern: "dd-MM-yyyy" }); // "23-08-1980" ``` -------------------------------- ### POST /api/logout Source: https://apidocs.rnd.mendix.com/11/client-mx-api/module-mx-api Logs out the current user and optionally restarts the client. ```APIDOC ## POST /api/logout ### Description Logs out the current user. Optionally, you can control whether the client restarts or reloads the page after logout. ### Method POST ### Endpoint `/api/logout` ### Parameters #### Request Body - **reloadOnSuccess** (boolean) - Optional - If true (default), the page reloads after logout. If false, manual success handling and reloading are allowed. ### Request Example ```json { "reloadOnSuccess": false } ``` ### Response #### Success Response (200) Indicates a successful logout. The response body may be empty or contain minimal confirmation. #### Response Example ```json { "status": "success" } ``` #### Error Response (500, etc.) Indicates an error occurred during the logout process. #### Error Response Example ```json { "error": "Logout failed." } ``` ``` -------------------------------- ### Login to Mendix Application Source: https://apidocs.rnd.mendix.com/11/client-mx-api/module-mx-api Attempts to log in a user to the Mendix application using provided credentials. Supports options for using authentication tokens and controlling page reloads upon success. ```javascript // Example with useAuthToken set to true and reloadOnSuccess set to false try { await login({ username: "fred", password: "fred's unguessable password", useAuthToken: true, reloadOnSuccess: false, }); console.log("Successful login."); // success handling } catch (error) { console.log("Login failed: ", error); // error handling } ``` -------------------------------- ### Navigate Back in Mendix UI Source: https://apidocs.rnd.mendix.com/11/client-mx-api/module-mx-api_ui Navigates one step back in the history, typically closing the current form. This method does not accept any parameters. ```javascript mxui.dom.back(); ``` -------------------------------- ### Show Confirmation Dialog in Mendix UI Source: https://apidocs.rnd.mendix.com/11/client-mx-api/module-mx-api_ui Displays a confirmation dialog to the user before executing a function. It returns a promise that resolves to a boolean indicating user choice. Optional parameters allow customization of button text. ```javascript await mxui.dom.confirmation({ content: "Do you really want to eat a burger?", okText: "I really do", cancelText: "I'll pass", }); ``` -------------------------------- ### Create MxObject using Mendix Client API Source: https://apidocs.rnd.mendix.com/11/client-mx-api/module-mx-api_data Creates a new MxObject for a specified entity. The method returns a Promise that resolves with the created MxObject instance or rejects with an error. This API is restricted in strict mode. ```javascript const cat = await create({ entity: "MyFirstModule.Cat" }); ``` -------------------------------- ### Subscription API Source: https://apidocs.rnd.mendix.com/11/client-mx-api/module-mx-api_data Manages subscriptions to changes in MxObjects, attributes, entities, or validation errors. Returns an Unsubscribable handle. ```APIDOC ## POST /api/subscribe ### Description Registers a callback to be invoked on changes in an MxObject, an attribute of an MxObject, any changes to MxObjects of a specific entity or validations errors in a specific MxObject. ### Method POST ### Endpoint /api/subscribe ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **scope** (Object) - Required - **params** (Object) - Required - **guid** (GUID) - Nullable - GUID to subscribe to. - **entity** (string) - Nullable - Entity to subscribe to. - **attr** (string) - Nullable - Attribute to subscribe to. - **val** (boolean) - Nullable - Subscribe to a validation on an MxObject. - **callback** (SubscribeEntityCallback | SubscribeObjectCallback | SubscribeAttributeCallback | SubscribeValidationCallback) - Required - Function to invoke when an update is available. ### Request Example ```json // Subscribe to all changes in an MxObject { "scope": {}, "params": { "guid": "123213", "callback": "function(guid) { console.log('Object with guid ' + guid + ' changed'); }" } } ``` ```json // Subscribe to changes in a specific attribute of an MxObject { "scope": {}, "params": { "guid": "123213", "attr": "Name", "callback": "function(guid, attr, value) { console.log('Object with guid ' + guid + ' had its attribute ' + attr + ' change to ' + value); }" } } ``` ```json // Subscribe to validations of an MxObject { "scope": {}, "params": { "guid": "123213", "val": true, "callback": "function(validations) { const reason = validations[0].getReasonByAttribute('MyAttribute'); console.log('Reason for validation error on attribute MyAttribute: ' + reason); }" } } ``` ```json // Subscribe to changes in a class { "scope": {}, "params": { "entity": "System.User", "callback": "function(entity) { console.log('Update on entity ' + entity); }" } } ``` ### Response #### Success Response (200) - **Unsubscribable** - Handle which can be passed to unsubscribe to remove the subscription. #### Response Example ```json // Returns a handle object { "handle": "some_subscription_handle" } ``` ``` ```APIDOC ## POST /api/unsubscribe ### Description Unregisters a callback registered through `subscribe`. Unregistering callbacks when they are no longer needed is important to prevent memory leaks. ### Method POST ### Endpoint /api/unsubscribe ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **handle** (Unsubscribable) - Required - Handle previously returned by a call to `subscribe`. ### Request Example ```json { "handle": "some_subscription_handle" } ``` ### Response #### Success Response (200) - **void** - Resolves when the callback is unregistered. #### Response Example ```json // No response body on success ``` ``` -------------------------------- ### Save File API Source: https://apidocs.rnd.mendix.com/11/client-mx-api/module-mx-api_data Saves a file to an MxObject, which should be an instance or specialization of System.FileDocument. Supports custom file options. ```APIDOC ## POST /api/saveFile ### Description Saves a file to an MxObject. ### Method POST ### Endpoint /api/saveFile ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **params** (Object) - Required - The parameters for saving the file. - **object** (MxObject) - Required - The MxObject to save the file to, should be an instance or specialization of System.FileDocument. - **blob** (Blob) - Required - The file data to save as a Blob object. - **fileOptions** (FileOptions) - Optional - Optional file options including name and image dimensions. ### Request Example ```json // Save a file with default options { "params": { "object": fileDocumentObject, "blob": myBlob } } ``` ```json // Save a file with custom name and image dimensions { "params": { "object": imageObject, "blob": imageBlob, "fileOptions": { "name": "profile-picture.jpg", "width": 800, "height": 600 } } } ``` ### Response #### Success Response (200) - **void** - Resolves when the file is successfully saved. #### Response Example ```json // No response body on success ``` ``` -------------------------------- ### MxObject - getOriginalReferences Source: https://apidocs.rnd.mendix.com/11/client-mx-api/MxObject Retrieves the original MxObjects referenced by a reference or reference set attribute, before any potential modifications. ```APIDOC ## GET /api/mxobject/getOriginalReferences ### Description Retrieves the original `MxObjects` referenced by a reference or reference set attribute. This returns the GUIDs of the objects as they were last committed. ### Method GET ### Endpoint `/api/mxobject/getOriginalReferences` ### Parameters #### Query Parameters - **attr** (string) - Required - The reference or reference set attribute whose original referenced objects to return. ### Response #### Success Response (200) - **GUIDs** (Array.) - An array of GUIDs representing the original referenced objects. ### Request Example ```javascript mxobj.getOriginalReferences("MyFirstModule.Ref"); ``` ### Response Example ```json [ "12345", "12346" ] ``` ```