Help with detecting changed values when form is closed
I am trying to implement some functionality where if a user makes changes to a record then either closes the form with the windows 'X', navigates away or uses a Cancel button without saving their changes, they are prompted that their changes have not been saved, do they wish to Save Now or Discard their changes. In most applications this is 'default' behaviour, but not in Mendix for some reason. I am using a custom Cancel (close) button with a microflow using the CommunityCommons.objectHasChanged java method to detect any changed values. So far, so good, I can detect if there have been changes. I looked at using the Confirm Microflow widget to pop-up the question, but this can only be used from a form button, not from a microflow. So instead, I used a separate form with Save and Discard buttons which I open as a modal dialog. So I can detect the unsaved changes. I can ask a question and run different microflows for each answer, but I can't apply the result to the record in question. Say they choose to discard, my microflow can include a Close Form action to close the modal question dialog, but I have no way to then close the original form in that microflow. Similarly, if they choose to save I can issue a commit, but cannot close the form. The only way I have found to close the original form is to do so in my custom Cancel button workflow before I pop-up the modal question. This sort-of works, but if I choose Discard, although the changes are not saved to the database, they are still cached locally and the changed (unsaved) data is still displayed if I re-open the record. They are also prompted to Save or Discard when they try to close the form after making no changes in this situation. So, is there a better way to do this? Can I leave the original form open while they are asked the question to Save/Discard (so they can see the data), yet close the form after getting their feedback? Can I clear the local cached data changes if they choose to discard?
Did you use a rollback with refresh?
I think a better way is to not use an extra form, but add an attribute to the object with the current state, and then combine custom visibility in your edit form with custom save/ cancel buttons.
You can add two close events in a microflow but only the last opened form will be closed. So you better close the edit form, then ask form confirmation to save or discard changes.
You can add a microflow trigger to ask the user if he wants to go back to the edit form to view his changes again.
With the discard event, you can rollback all changes to the last commit. This only happens on the service. In the rollback action you select 'Refresh in client' and the rollback of the object will be send to the client and the user has the unchanged object in the edit form. You have then not the problem that the user will be asked again of he will save the changes.
Joël vd Graaf
Hi – can you explain how your cancel microflow is working as described below? Specifically, what is the microflow doing when the object is changed. vs not changed?
“I am using a custom Cancel (close) button with a microflow using the CommunityCommons.objectHasChanged java method to detect any changed value”