Error in inserting data in table

i have created a table in which data get inserted when the user insert a value in decimal field,

For one document it is inserting the data but for second document it is showing error,

My code,

IF “Freight Amount” <> 0 THEN BEGIN
RecFrtLog.RESET;
RecFrtLog.INIT;
RecFrtLog.“Serial No”:=RecFrtLog.“Serial No”+1;
RecFrtLog.“Document No.”:=“No.”;
RecFrtLog.“Port of Discharge”:=“Port of Discharge”;
RecFrtLog.“Freight Amount”:=“Freight Amount”;
RecFrtLog.“User ID”:=USERID;
RecFrtLog.“Date and Time”:=CURRENTDATETIME;
RecFrtLog.INSERT;
END;

i have written this code in On Insert of sales header.

In your line: RecFrtLog.“Serial No”:=RecFrtLog.“Serial No”+1;

It will allways be 1 in your code.

In you use RecFrtLog as a Entry No. You need to go look in freight rate log entries.

You could do a findlast

Use

IF RecFrtLog.findlast THEN

RecFrtLog.“Serial No”:=RecFrtLog.“Serial No”+1

ELSE

RecFrtLog.“Serial No” :=1;

And you could change the line:

RecFrtLog.“Serial No”:=RecFrtLog.“Serial No”+1

to

RecFrtLog.“Serial No” +=1

Dear All,

my data is not inserting in table

var
LastRecFrtLogNo: integer;

IF “Freight Amount” <> 0 THEN BEGIN
RecFrtLog.RESET;
IF RecFrtLog.FINDLAST THEN
LastRecFrtLogNo := RecFrtLog.“Serial No” + 1
ELSE
LastRecFrtLogNo := 1;
RecFrtLog.INIT;
RecFrtLog.“Serial No”:=LastRecFrtLogNo;
RecFrtLog.“Document No.”:=“No.”;
RecFrtLog.“Port of Discharge”:=“Port of Discharge”;
RecFrtLog.“Freight Amount”:=“Freight Amount”;
RecFrtLog.“User ID”:=USERID;
RecFrtLog.“Date and Time”:=CURRENTDATETIME;
RecFrtLog.INSERT;
END;