12
Views
6
Comments
DELETE ENTITY DATA ON LOAD OR BEST PRACTISES
Application Type
Reactive

Good day. I am looking for best practices. So i have a button when someone clicks ADD a statement is added in the list (A table below) and a record created in the database.

When someone logs in again i want the list to be empty, however if someone had not deleted a record with the delete icon all records are still  there and are loaded automatically. How best can i delete the records in reactive web. On initialize? I just need best practises where can i run a loop deleting all records in that entity so that nothing is pre-polulated before clicking the ADD button. Screen shot below

I also don't want to slow the process  as it loops.

mvp_badge
MVP
Rank: #75

Hi Rudo,

If I understood the mentioned use-case correctly, the solution which I would suggest is to define and use a Local List data type variable instead of mapping the Screen Aggregate Output list as the respective Table Source property value. The defined Local List type Variable mapped with the Table widget, will hold the user input for temporary purpose and hence you don't need to explicitly clear/delete_All the Entity data before the screen load.


Hope this helps you!


Kind regards,

Benjith Sam

thank you for your quick reply. I once tried that but when deleting a record from a list (list remove) it took ages to delete and also i have to email the files and that's done in a traditional web app so i cant pass a list variable as an input parameter to email so either way i had to save data in an entity. 

mvp_badge
MVP
Rank: #75

Hi Rudo,

Sorry, I'm not able to understand why it's taking too long to delete the Local list record using ListRemove client action?

Solution 1: Using Local List type variable

1) Use/Map the Local List type variable as the Table Source

2) Add/Remove table record, which is not that difficult to achieve using ListAppend/ListRemove

3) Within the Send Email button client Action flow, before calling the actual server action (exposed from the Traditional Web app) - define a logic to dump/Insert all the Local List variable records to the respective entity for future reference.


Solution 2: Without using Local List type variable

  • Just introduce an additional logic before the end node within the Send email server action (defined in the Traditional Web app), --> define an Advance SQL node to clear/delete all the respective entity records and Hence, on every screen load the Aggregate result mapped with the Table widget will be empty.
  • I personally won't prefer this approach because unnecessary query execution is occurring during the screen load (Of which the result-set will be empty on every instance)


Note: I would suggest, to use the Local List data type variable approach for this use-case (Solution 1)


Hope this helps you!


Kind regards,

Benjith Sam

Rank: #67

Hi RUDO,


If I understood correctly, the user selects records but they are only submitted or in a "final status", when the user submits everything so user B does not see what user A is still adding. As I see it you can do one of two things:

  • Store the added information in memory (through local variable list for instance) and only save to the database when the user finally submits the whole thing, information is created in the Database - this means records are still not in the database when user B accesses it;
  • Store the record in the database with a status or flag IsDraft. When you add them to the table, they are created with IsDraft = True and when the user finally submits the whole thing, you update the flag of all records to FALSE. The query would have to be adjusted to only present records with IsDraft = False at the beginning so user B does not sees them when he accesses the screen.


Hope it helps.


Regards,
João

Thank you, For option A, i tried that but when i try to delete a record from the list (List remove) it took ages to delete but its instant when i call a delete action of an entity.

Option B can work but either way i am saving these records in a temporary entity and would like to delete the records once the user is done. Deleting the records on submit won't help i.e if someone clicks email-the files are emailed and if i delete the records there then i will lose the record on screen if data is refreshed and the user will need to add the statement again. Or i can get an error if the record remains and the user clicks download now in the database the record is no longer there.

I love the second option B but i will need to clear everything at some point....question where? on load? on initialize, on render? iterating too many records might slow the process.

Rank: #67

Hi RUDO,


For option B think about the IsDraft flag I mentioned as an IsActive flag. So you add an extra attribute to the record called IsActive and when you add the record to the database you set the IsActive = False. When the user presses submit, you update one by one the records with IsActive = False to have the IsActive = True. You won't need any screen event like OnInitialize, you just need to update the query to only show records with IsActive = True.


Also to add, it is not a very good practice to remove records on OnInitialize events as it is not clear for the user (nor the developer) what is happening leading to potential trouble maintaining that code, that's why the above strategy is a more intuitive one.


Let me know if it helps.


Regards,

João