Cancel button to rollback associations in datagrid

0
Dear experts,   I have the following situation (simplified): an Invoice can have 0..n InvoiceLine. In my Invoice_NewEdit page, I have a datagrid to add InvoiceLines. I add a few lines. When I click Cancel (the default button), the added lines are not rolled back. The same if I delete one line, then cancel, the line is actually deleted. I could understand why this is the default behaviour, but I would like to really cancel every change. I tried some suggestions from the forum like a custom cancel button to rollback the Invoice and the InvoiceLines through association but it does not seem to do what I need. Probably I could make a deepCopy of my object, but in the real situation I have Generalization that are not supported by deepCopy (I could if needed get rid of them), and I guess there is probaly an easier solution ? Many thanks for your suggestions!  
asked
2 answers
1

Hi Sam,

my solution would be to create a custom cancel button where I rollback the Invoice and InvoiceLines, and delete the InvoiceLines where the function isNew($InvoiceLine) is true. You can do this in a loop where you check for this condition, or if you're in Mx9 you can use the new feature 'Filter by Expression’ in the List Operation activity.

answered
0

Looks like, when a new invoice line is created, you are committing the object.

When deleting, you are deleting the invoice line object directly.

For new items:

- Create a new invoice line object and associate it with invoice object but dont commit it

- Do the commit, when you are saving the invoice → retrieve all invoice lines and commit it with commit action

- note: IsNew works only with objects that are not committed yet

For Delete items:

- only remove the association between objects but dont commit it yet

- When you save the invoice, retrieve all the associated invoice lines and commit

- Retrieve all the invoice lines without associated invoice lines and delete it

With this, your normal cancel should be working fine.

answered