How to prevent an entity from being commited after a file is uploaded?

0
Hello,   I have two entities: Entity and EntityFile. EntityFile stores the file documents and is associated with Entity. I have an Entity_Overview page. In the page there is a "New" button. When the button is clicked, I create a new Entity object and open the Entity_NewEdit page. There are of course some fields of the entity. I also use the file dropper widget to let the user upload files. The widget uses EntityFile entity and association to context associates it to Entity.   Normally, the user either clicks "Save" button and validation check is made before commiting the object. Or the user clicks the "Cancel" button and everything is rolled back.   However, the issue is, when the user uploads a file, the Entity is automatically commited. If the user doesn't click Save or Cancel buttons and does something else (e.g. reload the page), my Entity object remains commited which I don't want. Is there any way to prevent this?
asked
2 answers
0

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

answered
0

 

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.

answered