Uncommitted changes are lost when triggering custom on leave action and reopening page

0
Hi all, I’m facing an issue with the on leave action on a Mendix web page. Here’s the scenario: A user makes changes on a page without saving (i.e., uncommitted changes). They then click a "Show Home Page" button. This triggers a Custom on leave action, which checks for unsaved changes. If changes are detected, the current page is reopened, and a popup message is shown with a "Discard" option. The problem is: the uncommitted changes are lost when the page reloads — even before the user chooses to discard or keep the changes. Has anyone else faced this issue? Is there a way to preserve the uncommitted changes when reopening the page, so the user can decide what to do? Any suggestions or best practices to handle this scenario would be greatly appreciated! Thanks in advance.
asked
2 answers
0

Hi Prakhar,

 

I am not sure if I understand the issue thoroughly, let me put a possible solution in to some points;

 

1- Are you using ‘open page’ to show home page, then use a microflow instead.

 

2- The object you are working on would be parameter to this flow and instead of on leave action, you may check the changes here, in this microflow and handle ‘go to pages’ through decisions.So discard popup should be handled before opening next/home page.

 

Please let me know if I got the issue right,

Ferhat

answered
0

Hi Prakhar Pincha,

 

When you trigger a custom “on leave” action that reopens or refreshes a page, Mendix destroys the in-memory (uncommitted) object context and loads a fresh one, causing unsaved data to disappear. 

 

Recommended Approaches 

1.Save data temporarily before leaving the page. Instead of directly reopening the page, store the unsaved data in a non-persistent helper entity. Pass this object when reopening the page, so that the user’s edits are preserved. 

 

 Example flow: On leave action → Check for unsaved changes →If yes → Copy data to helper object →Reopen page with helper object context Then when the user confirms “Save”, copy data from helper → main entity and commit.  

--- 

2.Use a confirmation popup before navigation Instead of reopening the page automatically, show a popup with two options:

  • Save Changes
  • Discard Changes 

Only navigate after the user chooses. 

This avoids reloading the page before the user decides.

 

answered