How to create and save new one-to-many related data on same page?

0
Hi there, i am new to Mendix. I have two related entities: Book and Copy. One Book can have many Copies. When i add a new Book, i want to add directly at same page already the Copies. That means, the user has the opportunity to add Book-Copies before saving the Book to database.   Is this possible and if yes: how?   What i already did: Created two entities and 1:n relationship: Book, Copy Created a new Page: Book_NewEdit Created a Microflow: Create new Object "NewBook" => Show Book_NewEdit (always called for new Books before page) Book_NewEdit: Parameter: NewBook (Book) DataView: Data source => Entity => Book from page parameter generate the form elements for Book inside DataView, under Book forms: Data grid: Data source => Entity => DataView Copy_Bock > Copy generate the Data grid attributes for Copy generate a new Page for the "New Copy" Button: Copy_Newedit Copy_NewEdit: Parameters: Copy, Book There i am now. I changed for the page Book_NewEdit the property "URL" to "book/{Book/id}" - so every time i reload the page i see, there is a new BookId generated - so there must be an NewBook. When i want to create a new Copy, it generated a reference-selector-form with the list of existing Books. But the "new" Book created on the microflow is not available. I also tried to pass the NewBook object from Book_NewEdit to Copy_NewEdit as paramter to set default Book relationship to the NewBook to pass this attribute hidden and preselected, but i don't see at the reference-selector-form for the Book any options for that.   So, what do i have to change or is there a better approach to do this? Is there maybe a way to store the Copies temporary? Or is Mendix limited, so i have to create at a first page a Book without the Copies, and then i have a second page, where i can add the Copies? And if it is just the last solution, is there a way to avoid the reference-selector-Dropdown, so it sets for the user hidden the Book-Reference for each new Copy?   Thank you very much in advance!
asked
2 answers
2

Hi Stephan, you can checkout how I would build your page in this video.

https://www.youtube.com/watch?v=f5cv-BWTiYM

answered
0

What is the functionality when you click on the ‘Add Copy’ button?

This button should call a microflow (let say AddCopyToBook) which has a parameter of book.

In this microflow you create a new Copy object and associate it with the book.

If you want to make it ‘temporary’, make sure you don't commit the object. If not commited, the newly created copy is not yet stored in the database, thus only lives in the state of the client and will disappear if you don't save it.

answered