tl;dr; - I can't seem to trap errors when inserting records on the Dimension Set Entry. I have the code unit wrapped in IF NOT, but the appears to happen afterwards (keep reading for the code sample). It's stopping my NAS.
Per my last issue, i wrapped all my CRUD operations in individual code units in order to trap error messages and hand them back up to my .NET code. (original post is here
http://www.mibuso.com/forum/viewtopic.php?f=32&t=60482)
The code looks like:
IF NOT GoInsertARecord.RUN THEN BEGIN
ErrorText := GETLASTERRORTEXT();
CLEARLASTERROR();
HandErrorToCSharp(ErrorText);
END;
When I debug, I can step through and all the way out of GoInsertARecord. When I come back to this, and go to the next line, I get the following error message (which is fine I need errors):
"The dimension Set Entry already exists. Identification field and values: ..."
But then my code breaks completely, skipping the ErrorText assignment. I then have a STOP and RESTART event in my event viewer. This is the same behavior that I had before adding the IF NOT RUN.
Here's the output of the error in the event viewer:
Session ID: 1
User:
Type: Microsoft.Dynamics.Nav.Types.Exceptions.NavCSideException
Remappable: False
ErrorCode: 85132273
ErrorNumber: 1009
ModuleNumber: 19
SuppressMessage: False
FatalityScope: None
Message: The Dimension Set Entry already exists. Identification fields and values: Dimension Set ID='1',Dimension Code='ABC'
stackTrace: at Microsoft.Dynamics.Nav.Runtime.RecordImplementationHelper.MapException(NavCSideException originalException, NCLMetaTable metaTable, IRecordBuffer recordBuffer, Boolean makeNewExceptionRemappable)
One noticeable difference is that my typical errors are NAVDialogue exceptions, not NavCSideException. Maybe IF NOT RUN can't catch those? I should note that most entities seem to work just fine as described above. So far, dimension set entity is the only one failing like this. I'm not sure what's different with this entity.
Any help is appreciated.
Thanks.
Comments
code unit #1
Code unit #2
When I run this, I would expect a message box to pop up saying that it broke. I don't get one. I get the error message stating that I have a duplicate record. Code unit 2 breaks out BEFORE it hits the second line.
Thoughts?
Thanks.
There is a setting in the service tier that disables this behavior - I think it's 'Enable Debugging'. See also
http://msdn.microsoft.com/en-us/library/dd355341(v=nav.70).aspx
Also; never insert/modify directly in table 480/481 Dimension Set Entry. Use the library functions in codeunit 408.
Microsoft - Dynamics NAV
The question is still why doesn't it give an error?
What I meant is that the server actually doesn't insert into the database until the transaction commits - unless other factors forces it to. See article http://msdn.microsoft.com/en-us/library/dd355341(v=nav.70).aspx. That means that you can step over insert statements that will fail, but you don't find out until you try to commit.
Microsoft - Dynamics NAV
Thanks. I'll plug this into my larger code unit and cross my fingers.
<edit>
Totally worked. Thanks a bunch
</edit>