The Primary Keys of TransSales and TransSalesTransform is: Store No.,POS Terminal No.,Transaction No.,Line No.
It runs properly until a certain record saying that it is already exist when inserting even though it is not, also the record on TransSales is being deleted first before inserting data. I’m not sure if the FINDSET is repeating the same record on the source table (TransSalesTransform).
Thank you in advance!
Here is the image error:
It says already exist but that table has no record.
I am pretty sure that the two primary sortingkeys are not the same for the TransSales and TransSalesTransformTable…
Dont do a Findfirst with a Repeat - Do at least a FIND(’-’) or a FINDSET
the line TransSalesTransform.SETCURRENTKEY(“Store No.”,“POS Terminal No.”,“Transaction No.”,“Line No.”); is not needed as you on the line above did a RESET (Reset removes all filters and switches to to primary key).
You also dont need the BEGIN on the line IF TransSalesTransform.FINDSET THEN BEGIN (and you also have to remove the corresponding END line.
But first and foremost what are the FIRST line of the two tables in (Design, Table, Find table, Choose Design, and then View, Keys) ? (if you are running NAV 2018 or later).
Yes this will ofcourse work if it is only a matter of getting the records from one table to another. Weather it is ok or not depends of the usage of the data.
The main problem is that TransSales.INSERT cannot fail as the code is copying data from another table with the exact same primary key… I guess that it is not actually the line TransSales.INSERT; that is failing but another line in the code (we do not see all code )
You could try to just say
IF not TransSales.INSERT then;
to see if the error goes away (NOTICE this is NOT the right solution).
This is now ok. What I did is, I delete the TransSales Table and start new table by saving as the TransSalesTransform (the existing or the source) and named as new table (the TransSales) then remove the unnecessary fields and add the “Active Location Code” which is not present on the source. The codes are still the same.
I don’t know how it happen, though.
Anyway, Thank you for your feedback! it is highly appreciated.