"Another user hat..." for the xth time

Hi,
This topic has been discussed many times, unfortunately I have found in the forum posts no one that fits my current problem. To the point: A customer of us has a special field, which is calculated for each line ,among other things, based on the weight of the sales document. In each line it has the same value. If lines are now deleted, the weight inevitably changes, so the value of the special field must be recalculated. To do this, I call a codeunit in the OnAfterGetRecord trigger of the Subform 46, which in turn calls a code unit for the price calculation, in which, among other things, the value of this particular field is calculated. Unfortunately, MODIFYs are also executed on the sales line in these codeunits. If I now delete several sales lines at once, the well-known and popular error appears: "Another user has ...".
Mind you, this only happens if I mark several lines and delete them in one step. If I delete them successively with F4, it works.
In my distress I l have a COMMIT accommodated behind the Codeunit, which calls the Codeunit for the price calculation, (I hate this), without success.
The basic problem will be that I'm in the subform, and start a call that modifies the underlying records. The price calculation can also be called out of the form having the form 46 as a subform, then the problem does not appear. Is there a workaround for this? I've already considered something like closing the Form and then reopening it, but I do not know how. Does anyone have an idea?

With best regards

Answers

  • vaprogvaprog Member Posts: 1,140
    Pass the record along as a parameter.

    If you can't do this, call FIND (Or FIND('=')) after the function returned. If necessary add CurrPage.UPDATE(FALSE);

    But why do you do this kind of calculation in the OnAfterGetRecord trigger of a form? If this is for display purposes only, (which i doubt,) use a global variable. If it is used for some business process, use the database triggers instead.
    And why do you store the same value in each line? Store it in the header. If you need it to filter lines across documents, add a flowfield of type lookup to the line, looking up the value stored on the header.
  • FragenFragerFragenFrager Member Posts: 56
    Hello vaprog,
    first of all, I was mistaking, the special value is not the same in each line, it was a fortitute at my example.
    Well, I allready tried to put the logic in the OnDelete-Trigger of table 37. The problem is, that this special value is calculated also by the total weight of the document, which is a FlowField over all lines. In the OnDelete-Trigger, the deleted line unfortunately is still available for the calculation of the FlowField. It would have been great, if there would have been an OnAfterValidate-Trigger or something like that in table 37. Thanks anyway

    With kind regards
  • serdarulutasserdarulutas Member Posts: 50
    Have you ever tried setting a Boolean variable to TRUE (Bool_Recalculate) on OnDeleteRecord, OnInsertRecord, OnModifyRecord and then perform the following code in an appropriate place.

    IF Bool_Recalculate then begin
    RecalculateTotals(Rec);
    Bool_Recalculate = FALSE;
    END;
  • FragenFragerFragenFrager Member Posts: 56
    Hello Serdarulutas,
    meanwhile, I took the logic about calculating the discount from the statistic via F9 and modified it. I had to put the logic in the OnAfterDeleteRecord-Trigger of the form, because we have some adjustments which run the OnDelete-Trigger of the table 37. But thankyou very much for the Information.

    With kind regards
  • serdarulutasserdarulutas Member Posts: 50
    What about having another table where you have "Document No." and "Total Weight". You have a lookup flowfield to that field by the document number.


    And then for each line record, you can update the total value..
    * OnDelete: Calculate/Update totals without the existing line
    * Field OnValidate: Calculate totals for others + current value


Sign In or Register to comment.