I add two fields in Posted Transfer Shipment table Total Quantity and amount by using calcfield on Transfer Shipment Line table. To calculate amount against each item i use code and insert in Amount Field and modify that field. It work fine but is that when i create new transfer order it display an error message "An attempt was made to change an old version of a transfer header record. The record should be reread from the database."
This code i use to modify amount field.
TransShpLine.RESET;TransShpLine.SETAUTOCALCFIELDS(TransShpLine.ItemAmount);TransShpLine.SETRANGE(TransShpLine.Calculated,FALSE);IF TransShpLine.FINDSET THEN REPEAT TransShpLine."Document No." := TransShpLine."Document No."; TransShpLine."Line No." := TransShpLine."Line No."; TransShpLine.Amount := (TransShpLine.Quantity * TransShpLine.ItemAmount); TransShpLine.Calculated := TRUE; TransShpLine.MODIFY;UNTIL TransShpLine.NEXT = 0;MESSAGE('Done');
The reason is probably more than simple. You are setting a filter with Calculated = FALSE then you modify the record that you are at by setting a filter Calculated = TRUE and confuses the FINDSET. Besides from that there are several other issues in what you doing.
Your FINDSET is missing two parameters (Google the FINDSET command) and your MODIFY should ALWAYS be changed to MODIFY(TRUE).
ALSO the lines where you are setting the Document No and the Line No again is not needed.
Generally your code is wrong in many ways and you should really download the Training material for Dynamics NAV 2013 C/Side Solution Development to get the basic understanding of filtering and how to use records.
agree very basic mistakes in the code.
remove the following two lines from the program because it's a "primary key" fields and you cannot use Modify function.
TransShpLine."Document No." := TransShpLine."Document No.";TransShpLine."Line No." := TransShpLine."Line No.";
No that is NOT the problem!!!. The values of the the two lines are not changing and therefore not an issue, just not needed . ;-) The main problem is the FINDSET command. When you use a findset with a filtering on a field and you change the value of a field then you have to add parameters to the findset-command.
Thanks Palle for reply
Can you share Training material for Dynamics NAV 2013 C/Side Solution Development link?
You need to log on to partnersource to download it or Microsoft Borntolearn. The material is only free for Registered Microsoft Partners.
I don't have partner access that's i asked from you
yeah.. agree with you.
If you are a Microsoft partner then you can download it from:
https://mbs.microsoft.com/partnersource/northamerica/readiness-training/instructor-training-materials/course80437It is paid material for people that are not partners or customers - so I cannot give it to you. And if you are not a partner should should not even try to do development, because you are short in important information on the application and deveopment.
The source of the issue - is out of the FIND..-range with code below.
TransShpLine.Calculated := TRUE;
I would wirtee code:
TransShpLine: record "Transfer Shipment Line" ** I think it is right table :))))
TransShpLine2: record "Transfer Shipment Line" **
TransShpLine.RESET;TransShpLine.SETAUTOCALCFIELDS(ItemAmount);TransShpLine.SETRANGE(Calculated,FALSE);IF TransShpLine.FINDSET THEN REPEAT if TransShpLine2.GET(TransShpLine."Document No.",TransShpLine."Line No.") then begin TransShpLine2.Amount := (TransShpLine.Quantity * TransShpLine.ItemAmount); TransShpLine2.Calculated := TRUE; TransShpLine2.MODIFY; end; UNTIL TransShpLine.NEXT = 0;MESSAGE('Done');
P.S. But this point doesn not works correctly in the NAV 2018 (from VSC)