how can i retreive error messages
spiky_golden
Member Posts: 44
I have a code unit that insert data into a custom table. I Need to retreive and log all error occuring when Insert command fail. I Use a line taht looks like that :
Is there any way to get the error message why the code-unit goes into this condition.
IF NOT tmpRecord.INSERT THEN BEGIN
Is there any way to get the error message why the code-unit goes into this condition.
0
Answers
-
Hello,
If you are on 5.0 you can use a construct like the following to catch and log the eventual error caused by not inserting the record:IF NOT CODEUNIT.RUN(Codeunit::"The codeunit that inserts the record") THEN BEGIN IF GETLASTERRORTEXT <> '' THEN //save the error returned by GETLASTERRORTEXT into a table, for example CLEARLASTERROR; END;
Regards//Bogdan0 -
Here's the code i use
IF NOT tmpRecord.INSERT THEN BEGIN Window.UPDATE(2,'NOT DONE'); gOutStream.WRITETEXT( 'DealerId = ' + PadIt(FORMAT(tmpRecord."No."),5) + ' ; DealerName = ' +tmpRecord.Name + ' ; Error Code = ' + GETLASTERRORTEXT); gOutStream.WRITETEXT(); CLEARLASTERROR(); END
I always get GETLASTERRORTEXT = ''
but as far as I know if it goes in the IF condition it should have an error, right?0 -
No, as far as I know GETLASTERRORTEXT only works in the construction "If Codeunit.RUN() THEN...".
Have you tried to modify your code to use this context?//Bogdan0 -
BBlue wrote:No, as far as I know GETLASTERRORTEXT only works in the construction "If Codeunit.RUN() THEN...".
Have you tried to modify your code to use this context?
And to have correct error, the error must be fired, it means the INSERT must be used without return value (without the IF), else there is no error thus no error message in the GETLASTERRORTEXT...0 -
Well I'm pretty new in NAV... How can I use this kind of context? Should I make a new codeUnit with only the insert command, and then call it and check the error?0
-
spiky_golden wrote:How can I use this kind of context? Should I make a new codeUnit with only the insert command, and then call it and check the error?
That's correct. Or use the current one and change the logic, but do not use "if not insert then...", just "record.insert;...".
Then call this codeunit with the construction "If codeunit.run() THEN..."//Bogdan0 -
Well thank you I managed to make it work like this
CLEARLASTERROR; gWriteCodeUnit.Init(tmpRecord); IF NOT gWriteCodeUnit.RUN THEN BEGIN Window.UPDATE(2,'NOT DONE'); gOutStream.WRITETEXT( 'DealerId = ' + PadIt(FORMAT(tmpRecord."No."),5) + ' ; DealerName = ' +tmpRecord.Name + ' Error Code = ' + GETLASTERRORTEXT); gOutStream.WRITETEXT(); END;
Where the code in the gWriteCodeUnit looks like :Init(RecordSet : Record "Test Import") WriteRecords := RecordSet; ON RUN() WriteRecords.INSERT;
Maybe it's not pretty but it work just fine !0 -
You can do it better when you set the table as SourceTable on the codeunit (look into codeunit properties) and after that you can pass the record directly in Codeunit.RUN as parameter...0
-
How can you pass the record directly to the run command? The only Way I have found is by using a function...0
-
Read my answer once again... ;-)look into codeunit properties
Open the codeunit in designer, press Shift+F4... TableNo...0 -
Well it's great this way! Everything works just fine!
Thanks0
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