The System.FileDocument, due to it's implementation always autocommits. You hvae to handle this behaviour in custom logic.
A way to do this is to keep track of an attribute _isNew or something similar on true when uploading, setting it to false when saving, and removing any FileDocuments where _isNew is true when the session ends. You might also need some access rule xpath restriction to the owner, as else other users might have access while it's in the database
Hi Ahmer,
check these community question
https://community.mendix.com/link/space/korean-community/questions/141855
or use this method to solve the answer both are same if you understand the below answer gothrough the above posted link
Automatic Commit After File Upload:
When a file is uploaded using the file dropper, it automatically commits the file to the system.Add Attribute (isSaved):
Add an attribute named isSaved to track whether the file has been successfully committed. After committing the file, set isSaved to true.Retrieve from Database with Condition:
When retrieving documents from the database, filter the results by checking the condition isSaved = true.This ensures that only the uploaded and committed documents are displayedcheck the list count it will show correctly.
Hello Ahmet,
Did you any Solution for this?
Hi Ahmet, this happens because uploading a file via the file dropper widget forces the parent Entity to be committed immediately, to establish the association with the EntityFile. As a result, even if the user hasn’t clicked “Save,” the Entity gets saved prematurely. It was a widget features
Alternative Solution:
Create the Entity only after saving don’t create the Entity when clicking “New.” Instead, wait until the user clicks “Save” to create and save it.
Store files temporarily let users upload files to a temporary place before the Entity exists. After saving the Entity, link the files to it.
Clean up if canceled if the user cancels or leaves the page without saving, delete any unfinished Entities or files that were saved automatically.
Files must link to a saved Entity, the Entity gets saved early. To avoid this, delay creating the Entity or clean up unwanted records.
I hope this one helps you! :)
Hello Ahmet,
You may try to avoid create Entity Object and show page on click on 'New' button.
instead,
You may try to call a MF on click on 'New' button and try creating Object of Entity inside that MF and then show Page.
This way, I hope it won't auto commit Entity Object.
Thanks.