Hello there,i am new to OutSystems and my Use Case is as follows:I have two Entities: Book, BookCopyTo a Book, you can add more than one BookCopy (One-To-Many-Relationship).I have a Screen, where i want to add a new Book, including book copies. On it is an empty Form with inputs for Book attributes. And an empty table widget, which will later list all the related BookCopy records. It also contains an "add BookCopy"-button, which opens a PopUp, where i can add those.
ProblemOutSystems is adding an URL-Parameter with the id 0 (?BookId=0). If i just want to add a new BookCopy directly to the database, the BookCopy will be related to the Book-id 0. This happens globally, so when there are multiple users adding new books, they all will see the same BookCopies. So this does not work out.What is the correct way, to build this Screen properly?First approach: getting max(BookId)+1When i call the Screen, i run a Client-/Server-action which gets an unique id. For example like in an Oracle DB, where i can get a sequence value, without creating an new entity. There was no way, how to get the next value of the BookId, without adding an Book. Online advices said, i can get the actual max-value of the BookId and add 1. But if there are multiple users, this could run into the problem, that several users get the same id or not? Is there a way to get a new unique id of an entity without adding directly a new DB-row?Second approach: store BookCopies temporaryI try to temporary store the BookCopy entries. If i filled the whole Screen form, i try to save everything with a Server-action, first the Book, then the temporary entries stored, related to the new created BookId.But i have no idea, how this works in OutSystems Reactive Apps? Forum Postings told me " to store temporary purpose till you are hitting the server to store the database, we use structures." - So i created a structure for BookCopy, but i cannot connect this to my table widget. Also read about to store the structure in a local variable, but same outcome – can’t connect to the table widget. Is there a way to store BookCopies temporary and if yes, how?Can someone please help me with this?
Hi
I think for saving this data you will create a single server action. In this server action you need to pass book data and list of book orders. First you will save book data. Use book id returned by create action of book data and create records of book orders in different table. In case of create no need to worry about book id just left it blank or nullIdentifier().
Now in case of edit you can create a data action where will get the book data and book orders filtered by book id. So now you can show this data in any way you want.
Hope it clear the scenario.
Regards
Hi,
thank you for your fast respond. I got your point, but this is not the problem.
The problem is, that i have to store and display the BookCopy-Entity-Data, before i have saved the related Book-Entity. Like in my screenshot, the user uses first the "Add copy" action, where the BookCopies are then displayed in the table widget, and after that they click the "Save new Book" button.
To show book data you will create a local variable of list Tye with book record data type. Set this list as source of book records table.
When user clicks on add copy button you can open one popup where user will store copy data. On save of popup append copy data to your local list. So now it will be visible in table as well.
Later when user clicks on save book button will pass this local list to server action which I mentioned in last reply.
As you correctly stated you can use Second approach. you can hold value in a temporary list variable (create a local variable in screen of data type list of BookCopy)
when you click Add copy > pop up open> fill the value> you must have save/enter(on click of it, use List Append system client action to append the value to local list).Use this local list to bind the table to show your book copy results. And then on click on Save button, first save the Book (you will get the id) and then save your book copy data using that Book Id. Hope this helps.
Hi Stephen,
If I understand correctly, then your table widget uses the same local list in which you append the data. Also in your table , you are having multiple columns, hope you have bind the correct expression values in rows in the table
@Vikas Sharma @Puja Rani,
i got your point and it seems to be the right direction. I can add now BookCopies to the local variable and i can save the BookCopies together with the related Book, they get stored then correct in the database. Thank you very much for this!
But i still have a problem with the table widget. When i add a BookCopy in client action with ListAppend-action, in the table it shows up a new row entry, but the columns are all empty. The table source is the local variable (with datatype BookCopy List) and the column sort attribute is related to the local variable attributes. When i debug the client action, i see, that the new BookCopy is inside the local variable. Is there something additional to do?
If I understand correctly, then after you save BookCopy and Book details, your saved records are not showing in the table on your screen... right? If yes, then in the screen table widget to view your saved records you can use directly the aggregates (if need to show data from both Book & Book Copy table , can use aggregate and add join with both table) to display he data. The local list we used was just to store the value of particular Book/BookCopy only temporarily. You should use List Clear on save logic before logic ends to reset your local list.
Hi Puja,
no, its one step before, when i temporarily save the BookCopies. For each BookCopy, it adds a empty row in the table, after i used ListAppend-action to local variable.
Wenn i save then later Book+BookCopy, everything is correct stored in DB.
So i guess there is a problem with the table widget combined with the source local variable with datatype BookCopy List?
I attached an screenshot of my settings. Left is the client action, where i ListAppend the BookCopy. When the whole client action is completed, in the App the empty row is added (see the screenshot from my post before). In the middle is the local variable, on the right the table, with the variable as source. On the right bottom is an example of the first table column header, where the attribute is connected. And Exemplar = BookCopy in my language. Somewhere i did something wrong or i missed something, that it is shown properly in the table widget?
Yes, that was the missing setting, thank you very much Puja!
Just now saw your updated comment with image . I think you have misinterpret the use of table widget. As you said - "first table column header, where the attribute is connected " - when we bind the attribute as label says Sort attribute when we click on column header it sorts the table based on that column. In order to display list data you need to add expression in the row cell and bind to table source list. Just for your reference, you can take a look at document for table widget.
Glad your issue is solved :)
Hi @Stephan Nöhmeier , Can you share the OML.
Regards,
Vinod