You can use mx.session for storing your NPE. Created an example using buddy chatgpt: See https://chatgpt.com/c/cd885b74-898b-4aab-a8f8-4ba7e80212be
Yes, you can use mx.session in Mendix to keep your non-persistent entity alive. By storing the non-persistent entity in the client-side session storage, you can ensure it persists for the duration of the session. Here’s how you can achieve this:
Using mx.session to Keep Non-Persistent Entity Alive
Create a Non-Persistent Entity
Create a Nanoflow to Initialize the Non-Persistent Entity
Retrieve the Non-Persistent Entity from the Session
Step-by-Step Implementation
Step 1: Create Non-Persistent Entity
Step 2: Create Nanoflow to Initialize and Store Entity
Create Object
JavaScript Action to Store Entity in Session
// JavaScript Action to store entity in session
var entityJson = JSON.stringify(mx.data.create({
entity: 'MyModule.SessionContainer',
guid: entity.getGuid(),
attributes: entity.getAttributes()
}));
sessionStorage.setItem('sessionContainer', entityJson);
Add JavaScript Action to Nanoflow
Step 3: Create Nanoflow to Retrieve Entity
JavaScript Action to Retrieve Entity from Session
// JavaScript Action to retrieve entity from session
var entityJson = sessionStorage.getItem('sessionContainer');
if (entityJson) {
var entityObj = JSON.parse(entityJson);
var entity = mx.data.create({
entity: 'MyModule.SessionContainer',
guid: entityObj.guid,
attributes: entityObj.attributes
});
return entity;
} else {
return null;
}
Add JavaScript Action to Nanoflow
Actually this could well get added to the NanoflowCommons module by Mendix.