Strange Error - Document Dimension Already Exists

Jonathan2708Jonathan2708 Member Posts: 552
Hi,

I have a custom Dataport routine that creates sales invoices from a CSV file. The routine has been working fine and ran successfully last night, however this morning a strange error has occurred :

"Document Dimension already exists
Table=37, Document Type=Invoice, Document No.=063477748, Line No.=10000, Dimension Code=COSTCENTRE"

The error occurs on a 2 line invoice, when creating the second line (line no. 20000), when I am setting the line type :

VALIDATE(Type, Type::"G/L Account");

The "Sales Line".Type OnValidate() trigger inturn calls :

DimMgt.DeleteDocDim(DATABASE::"Sales Line","Document Type","Document No.","Line No.");

Which has the following code :

DocDim.SETRANGE("Table ID",TableID);
DocDim.SETRANGE("Document Type",DocType);
DocDim.SETRANGE("Document No.",DocNo);
DocDim.SETRANGE("Line No.",LineNo);
IF NOT DocDim.ISEMPTY THEN <<- ERROR OCCURS HERE
DocDim.DELETEALL;

The error occurs when checking if there are any existing dimensions for the new line, I can see no code trying to add a dimension and am therefore very confused as to why I'm getting the above error.

Even stranger still is that this error only occurs on the production server version, I cannot reproduce the error on my PC, even though all objects are the same version. The Dataport ran fine last night.

Any ideas as to what might be causing this?

Version is NAV 2009 Classic Client, using SQL Server 2008

Thanks

Jonathan

Answers

  • krikikriki Member, Moderator Posts: 9,110
    The reason you get the error on the ISEMPTY is because you inserted dimensions that already existed. But the insert was retarded because of the bulk-insert feature of NAV (is NOT the same as the SQL bulk insert).

    It works as this:
    The inserts you do in a table are not send to the database immediately but are buffered. Once you do some OTHER action on that table (GET,FIND,ISEMPTY,MODIFY,DELETE,...) the buffered records are sent to the database and thus only in that moment the existing-record-error comes up.

    To debug it, after doing an INSERT on that table, you can use a reset on the dimensions table that generated the error and do an "IF DocDim.ISEMPTY THEN ;".
    This will send the buffered records to the table and an error will come up directly if something already exists.

    The buffering is very good for performance reasons, but debugging errors gets quite difficult.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Jonathan2708Jonathan2708 Member Posts: 552
    Many thanks kriki you're a star.

    Being able to force the send to DB enabled me to get a better idea of where the problem was. Turns out the G/L account I was trying to add a dimension for already had a default dimension setup for it, hence the 'already exists' error.

    Useful to know anout the buffering.

    Thanks

    Jonathan
Sign In or Register to comment.