Issue with deleted child records reappearing after form submission in update interface

Hi Community,

I'm working on an Appian interface for updating a parent table(BaseOilOrConcentrate) which includes a related editable grid of child table(WIW_OIL_SPEC_CONTROLES). I use a rule-backed component (rule!WIW_gridLayout_specs_Oil) to display and manage this grid.

When I delete a row from the grid (child spec), it gets removed from the database immediately (which is expected). However, after clicking the Submit button to finalize the update, the deleted child records reappear in the database.

Has anyone encountered a similar situation? Is there a recommended approach to persist deletion state across the interface and process model without modifying the rule?

Thanks in advance for any suggestions!

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    Make sure the rule inputs which are passed from the form to process on Submit button action does not have the deleted rows. In this case, the delete might be deleting row from database from interface but some variable still has the deleted row and when in process write to records in done, deleted row is reinserted. So on deletion, remove the row from variable holding entire grid data as well. 

  • The problem is that I can't modify the rule that contains the database deletion logic — rule!WIW_gridLayout_specs_Oil, which is called like this:

    apex
    CopyEdit
    rule!WIW_gridLayout_specs_Oil( oilSpecControles: ri!oilSpecControles, isRequired: true, concentreBaseOilId: ri!idBaseoil, deleteFromDB: true )

    And in the submit button, I currently only have:

    apex
    CopyEdit
    primaryButtons: { a!buttonWidgetSubmit( label: index(local!labels, "submit", {}), style: "PRIMARY", value: true, skipValidation: true ) }

    So the issue is that although the row is deleted from the database in the interface, it's still present in ri!oilSpecControles, and when the process writes the data, the deleted row gets reinserted. Since I can't update the rule to also remove the row from the variable, I need an external way to update ri!oilSpecControles before submitting.

  • 0
    Certified Lead Developer
    in reply to Abdessamad Bencheraik

    In this case, as you cannot modify rule WIW_gridLayout_specs_Oil, In the saveInto of submit button you can do a difference between ri!oilSpecControles and the query from database for the rows in grid. 

    E.g. initially ri!oilSpecControles can have 3 rows, say you deleted row 2nd from the grid. Now when  you submit ri!oilSpecControles will have 3 rows still but your database will have only 2 rows. So, on submit action or inside the process before you do write to records remove the row not present in database AND where id is not null. 

    As its a editable grid below conditions you need to handle:

    1. User adds new row - ri!oilSpecControles  will have it but database won't. But id will be null for new row. So when checking difference consider only the rows where id is not null

    User updates a row - ri!oilSpecControles and database both will have this row. So it should be as is. When checking difference this row won't be removed

    3. User deletes a row - ri!oilSpecControles will have this in your case but database won't. Also, id will be available in the ri!oilSpecControles  for this row. So when checking difference between database rows and ri!oilSpecControles this row should be removed from ri!oilSpecControles . Now when you do write to records in process deleted row won't be written to db again. 

    So checking id (primary key) value while doing difference operation is crucial and this can help you fix the issue you are having.

    P.S. You have marked your previous comment as Answer. It can be misleading, please update it to reflect the comment having correct answer instead.

Reply
  • 0
    Certified Lead Developer
    in reply to Abdessamad Bencheraik

    In this case, as you cannot modify rule WIW_gridLayout_specs_Oil, In the saveInto of submit button you can do a difference between ri!oilSpecControles and the query from database for the rows in grid. 

    E.g. initially ri!oilSpecControles can have 3 rows, say you deleted row 2nd from the grid. Now when  you submit ri!oilSpecControles will have 3 rows still but your database will have only 2 rows. So, on submit action or inside the process before you do write to records remove the row not present in database AND where id is not null. 

    As its a editable grid below conditions you need to handle:

    1. User adds new row - ri!oilSpecControles  will have it but database won't. But id will be null for new row. So when checking difference consider only the rows where id is not null

    User updates a row - ri!oilSpecControles and database both will have this row. So it should be as is. When checking difference this row won't be removed

    3. User deletes a row - ri!oilSpecControles will have this in your case but database won't. Also, id will be available in the ri!oilSpecControles  for this row. So when checking difference between database rows and ri!oilSpecControles this row should be removed from ri!oilSpecControles . Now when you do write to records in process deleted row won't be written to db again. 

    So checking id (primary key) value while doing difference operation is crucial and this can help you fix the issue you are having.

    P.S. You have marked your previous comment as Answer. It can be misleading, please update it to reflect the comment having correct answer instead.

Children
No Data