Can't trap errors on Dimension Set Entry

shelbydzshelbydz Member Posts: 14
edited 2014-03-04 in NAV Three Tier
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

  • shelbydzshelbydz Member Posts: 14
    A quick update. i wrote a pair of code units to demonstrate the problem:

    code unit #1
    OnRun()
    DimensionSet.INIT;
    DimensionSet."Dimension Set ID" := 100;
    DimensionSet.INSERT;
    //insert another, duplicate record to error this out
    DimensionSet.INIT;
    DimensionSet."Dimension Set ID" := 100;
    DimensionSet.INSERT; 
    

    Code unit #2
    OnRun()
    IF NOT CodeUnit2.RUN THEN 
        MESSAGE('Hey you broke something');
    

    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.
  • BardurKnudsenBardurKnudsen Member, Microsoft Employee Posts: 137
    This is due to the use of 'buffered insert' where the records are inserted 'as late as possible', which may be at COMMIT.
    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.
    Bardur Knudsen
    Microsoft - Dynamics NAV
  • mdPartnerNLmdPartnerNL Member Posts: 802
    I think the shelbydz only added the second .insert command the create an error.

    The question is still why doesn't it give an error?
  • BardurKnudsenBardurKnudsen Member, Microsoft Employee Posts: 137
    Sorry for not being clear before.
    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.
    Bardur Knudsen
    Microsoft - Dynamics NAV
  • shelbydzshelbydz Member Posts: 14
    That looks like it'll work. If I add COMMIT; to the end of the 1st code unit, I get the right error message.

    Thanks. I'll plug this into my larger code unit and cross my fingers.

    <edit>
    Totally worked. Thanks a bunch
    </edit>
Sign In or Register to comment.