Hi
I have searched the forum but I cannot find anything that relates to this.
When I insert a record into a table the first time it is run there is no problem, however the second time it's run (assuming I haven't closed the originating form) then I get an issue.
I have tracked it to here in On Insert on the table.
IF "No." = '' THEN BEGIN
NoSeriesMgt.InitSeries('QC-COFA',mSeries,0D,"No.",mSeries);
END;
The first time "No." is blank so there is no problem. For some reason on the second insert (this is manually run) the "No." isn't blank and of course it throws a "Number already exists" problem.
I am sure this is something simple but any help greatly appreciated.
0
Answers
I think that is wrong since it uses a constant: 'QC-COFA'. You should avoid this.
Is this your code?
Number series gets updated, everything runs perfectly on first execution.
RIS Plus, LLC
A record gets inserted after picking the next number correctly. The next time it's run (assuming the originating screen hasn't been closed and reopened) it fails at the above point.
The trigger on the table gets fired and "No" isn't blank the second time, it takes the "No" from the previous insert by default.
The code
CofAHeader.INIT;
CofAHeader."Lot No." := LotNumber;
CofAHeader."Item No." := ItemNo;
CofAHeader.Description := Description;
CofAHeader.Quantity := QtyLcl;
CofAHeader."Active Version" := 1;
CofAHeader."Creation Date" := TODAY;
CofAHeader."Batch Multiple" := LotQtyLcl;
CofAHeader.INSERT(TRUE);
Put this before the INIT Statement.
CLEAR(CofAHeader);
or
CofAHeader."No." := '';
Hope this helps
Albert
DenSter gave you the tip which on re-reading would also have given you the solution
Albert
Make it a habit of taking care of primary key values every time you use INIT. You can do this by either of two ways:
1 - Use CLEAR, which destroys the variable, and when INIT initializes the record, the primary key fields don't have a value. This is an implicit way of clearing the primary key fields.
2 - Do INIT first, and then set the primary key fields manually. This is an explicit way, which is very useful when you want to create a whole batch of records in a table with a compound primary key, and you don't want to have to set all primary key fields every time. For instance, you are creating a new sales invoice:
RIS Plus, LLC
Cheers guys.