IF VALIDATE THEN ...

boywonder
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
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..... :?
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

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..... :?
0
Comments
-
If you are on version 5 or higher then you can read the help for Error Handling -> GETLASTERRORTEXT.0
-
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...?0 -
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...0 -
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.0 -
I get it !
Brilliant, fantastic, thank you all =D> =D>0 -
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);
0 -
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 it0 -
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.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 file0 -
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"Money is likewise the greatest chance and the greatest scourge of mankind."0 -
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!0
-
einsTeIn.NET wrote: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
yes i did realize and already changed it becomeIF 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 file0 -
What is still wrong?"Money is likewise the greatest chance and the greatest scourge of mankind."0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions