C. Griffin
C. Griffin

Reputation: 681

Dynamics AX 2009: Deleting discounts and added charges

Essentially, what I'm doing is this:

  1. On insert, delete, or update on the SalesLine table, I'm checking the ProductCode of that line and determining whether or not a discount or miscellaneous charge applies
  2. I have lookup tables for the charges and discounts
  3. When any changes are made, I have to effectively remove the discounts/charges, because the newly modified SalesLine might not qualify for the charges/discounts

I have code that is doing what is described above -- but with the following side-effect:

What would be the best way to erase the added-by-code discounts or charges when the parent line is deleted, that won't cause the form to blow up if a user selects those same lines for deletion?

Thanks in advance, this thing is driving me crazy!

EDIT: The specific error that I receive when the cached Form records try to get deleted is this:

Cannot edit a record in Order lines (SalesLine).An update conflict occurred due to another user process deleting the record or changing one or more fields in the record.

Upvotes: 0

Views: 1946

Answers (1)

Jan B. Kjeldsen
Jan B. Kjeldsen

Reputation: 18051

The most obvious way to delete the added-by-code discounts or charges would be to add your table in the delete actions of the salesLine table with option Cascade. Also make a table relation on your table to the SalesLine talbe. In this way your records are deleted automatically. I would not do this if the discounts/charges are stored as sales lines though.

The error message make me guess, that you delete other sales lines, when deleting a sales line:

  1. When deleting a "real" sales line you delete discount or charge lines.
  2. When doing multi-line delete the #2 line has been deleted by the #1 line delete, but the form buffer has not been updated and the delete fails. This is effectively what the error messages tells you, a line has been updated since the record was read by the form.

Update for the delete problem:

  1. Remove your code from the SalesLine delete methods.
  2. Create a set of recId to be deleted later, populate in the salesLine datasource delete method.
  3. Delete the lines later (maybe from the active method), if the set is not null.

Upvotes: 1

Related Questions