IF VALIDATE THEN ...

boywonderboywonder Member Posts: 179
I think the answer to this is probably a straightforward "no", however:

I create Item records in a temporary table ready for transfer to another company..

The transfer of the records from temp table to real Item table must be auto. and if there is a validation error then a run-time error must be avoided and instead an entry put in an error table. Fine in terms of field type and length validation I use IF NOT EVALUATE THEN ErrorLog.

But I want FULL validation - as the new records are created I want to call the VALIDATE trigger of each field ie.

Item.VALIDATE("No.",Temp."No.);

AND NOT Item."No." := Temp."No."

The problem is that if the VALIDATE fails then an run-time error occurs which I can't easily trap as IF VALIDATE THEN has never been an option :cry:

So to solve I can write all the code from the VALIDATE triggers into my routine and trap any problems there :shock: :shock: :shock:

But that's an insane amount of work and a nightmare to maintain.....so the question (finally!) is.....

Without writing all the Item table VALIDATE code into my routine is there another way..... :?

Comments

  • kapamaroukapamarou Member Posts: 1,152
    If you are on version 5 or higher then you can read the help for Error Handling -> GETLASTERRORTEXT.
  • boywonderboywonder Member Posts: 179
    Ah ha V5 it is then 8)

    It says in the documentation 'you can setup Dynamics NAV to continue even if a runtime error occurs' but no mention of how??

    I don't want any error messages to display, all must be trapped and written to table...?
  • BeliasBelias Member Posts: 2,998
    search the forum for "if codeunit.run then"
    you'll find the way...otherwise (i'm sponsoring a thread of mine :) )
    http://www.mibuso.com/forum/viewtopic.php?f=5&t=31763
    anyway, even in my thread i use the if codeunit.run...
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • kapamaroukapamarou Member Posts: 1,152
    I think you need to create a codeunit and then do something like:

    If NOT MyCodeUnit.RUN THEN BEGIN
    MyLastError := GETLASTERROR;
    MyLOG.INSERT(MyLastError.);
    END;

    Something similar. Search the forum for GETLASTERROR and you'll find plenty of info.
  • boywonderboywonder Member Posts: 179
    I get it !

    Brilliant, fantastic, thank you all =D> =D>
  • primeapprimeap Member Posts: 37
    kapamarou wrote:
    I think you need to create a codeunit and then do something like:

    If NOT MyCodeUnit.RUN THEN BEGIN
    MyLastError := GETLASTERROR;
    MyLOG.INSERT(MyLastError.);
    END;

    Something similar. Search the forum for GETLASTERROR and you'll find plenty of info.


    This would be a correct syntax:
       IF NOT CODEUNIT.RUN(CODEUNIT::MyCodeunit) THEN
          MESSAGE(GETLASTERRORTEXT);
    
  • BeliasBelias Member Posts: 2,998
    no, primeap...the code you wrote has not a lot of sense...you are evading an error, but you show a message...what's the point in doing this? it's better to log the error in a table, instead, isn't it?
    EDIT: maybe you meant that the instruction is GETLASTERRORTEXT and not GETLASTERROR...ok, got it
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • kapamaroukapamarou Member Posts: 1,152
    Belias wrote:
    you are evading an error, but you show a message

    If I remember correctly, at least in some versions, MESSAGE windows can lead to locked resources if they stay open...
  • julkifli33julkifli33 Member Posts: 1,087
    kapamarou wrote:
    I think you need to create a codeunit and then do something like:

    If NOT MyCodeUnit.RUN THEN BEGIN
    MyLastError := GETLASTERROR;
    MyLOG.INSERT(MyLastError.);
    END;

    Something similar. Search the forum for GETLASTERROR and you'll find plenty of info.
    from your code is like this
            If NOT MyCodeUnit.RUN THEN BEGIN
            MyLastError := GETLASTERROR;
            MyLOG.INSERT(MyLastError.);
    
    but it's not working for me
    any idea?
    .
    .
    .
    .
            SH.Imported := TRUE;
            IF NOT SH.INSERT(TRUE) THEN
            StrLine2 := GETLASTERRORTEXT
            ELSE
            SH.INSERT(TRUE);
            END;
    

    when it want to insert to the table, sometimes have duplicate data
    i want to catch that error message and then store it in log file
  • rhpntrhpnt Member Posts: 688
    boywonder wrote:
    and if there is a validation error then a run-time error must be avoided and instead an entry put in an error table.
    You should take a look at the standard NAV data migration functionality.
  • einsTeIn.NETeinsTeIn.NET Member Posts: 1,050
    julkifli33 wrote:
    .
    .
    .
    .
            SH.Imported := TRUE;
            IF NOT SH.INSERT(TRUE) THEN
            StrLine2 := GETLASTERRORTEXT
            ELSE
            SH.INSERT(TRUE);
            END;
    

    when it want to insert to the table, sometimes have duplicate data
    i want to catch that error message and then store it in log file
    This way you'll insert the information twice. If "IF Record.INSERT(TRUE) THEN" is true then your record is already inserted. No need to inserted it again in "ELSE".
    "Money is likewise the greatest chance and the greatest scourge of mankind."
  • rhpntrhpnt Member Posts: 688
    The data integrity check must happen at the import in the temporary table and not at the destination table. Again, the standard data migration functionality has all you need or wish to do. No programming needed!
  • julkifli33julkifli33 Member Posts: 1,087
    julkifli33 wrote:
    .
    .
    .
    .
            SH.Imported := TRUE;
            IF NOT SH.INSERT(TRUE) THEN
            StrLine2 := GETLASTERRORTEXT
            ELSE
            SH.INSERT(TRUE);
            END;
    

    when it want to insert to the table, sometimes have duplicate data
    i want to catch that error message and then store it in log file
    This way you'll insert the information twice. If "IF Record.INSERT(TRUE) THEN" is true then your record is already inserted. No need to inserted it again in "ELSE".

    yes i did realize and already changed it become
    IF NOT SH.INSERT(TRUE) THEN
            StrLine2 := GETLASTERRORTEXT
    

    but i think still wrong
    what i want is if failed to insert... then getlasterror put in variable strline2
    from this strline2, i want to put it in log file
  • einsTeIn.NETeinsTeIn.NET Member Posts: 1,050
    What is still wrong?
    "Money is likewise the greatest chance and the greatest scourge of mankind."
Sign In or Register to comment.