I'm running into a bizarre situation where calling COUNT on a table is generating a very unexpected error. The error is as follows:
The Dynamic Move Line already exists. Identification fields and values: ...
As you can see, this is the typical error that you would get when attempting to insert a duplicate key entry into a table. The error is raised from the following code line:
IF DynamicMoveLine.COUNT > 1 THEN
What makes this yet even stranger is that prior to this code (in my test case) I have called DELETEALL before inserting a single line. Obviously if all the records are deleted and one entry is then inserted, there should be no key collision. I have never in my life seen Navision generate a "line already exists" error from a call to the COUNT function. I'm assuming this must be a bug in the new RTC nav engine. Has anyone else seen this happen? Does anyone know what is going on here?
Thad Ryker
I traded my sanity for a railgun
Answers
In later versions of NAV you can disable this bulk/delayed insert functionality, there is an option called "Enable Buffered Insert" which you can untick in the Administration tool to stop this delayed behaviour - you'll then see exactly where the error is coming from (i.e. the INSERT statement)
I traded my sanity for a railgun
After your DELETEALL you must be INSERTing some records (otherwise there'd be no point doing a COUNT?) so it's during these INSERTs that you are adding 2 records with the same key.
I traded my sanity for a railgun