Error Handling

schoolkid
Member Posts: 103
Dear all,
need your help on this.
i have a sales buffer table in which i populate sales orders and then move them to sales header table.when the data in the buffer table has some errors it has to mark the particular record as error and move on to the next record.
i wrote the following code but seems that it doesnt work
IF "Sales Header Buffer".FIND('-')THEN BEGIN
REPEAT
"Sales Table".INIT;
"Sales Table"."Document Type" := "Sales Header Buffer"."Document Type";
"Sales Table"."No." := "Sales Header Buffer"."No.";
"Sales Table"."Sell-to Customer No." := "Sales Header Buffer"."Sell-to Customer No.";
"Sales Table".VALIDATE("Sales Table"."Document Date",TODAY);
"Sales Table".LOCKTABLE;
IF NOT("Sales Table".INSERT)
THEN BEGIN
"Sales Header Buffer"."Error":= TRUE;
"Sales Header Buffer".MODIFY(TRUE);
END
ELSE begin
message('Imported Successfully';)
END;
COMMIT;
UNTIL "Sales Header Buffer".NEXT = 0;
END;
any help on this please
need your help on this.
i have a sales buffer table in which i populate sales orders and then move them to sales header table.when the data in the buffer table has some errors it has to mark the particular record as error and move on to the next record.
i wrote the following code but seems that it doesnt work
IF "Sales Header Buffer".FIND('-')THEN BEGIN
REPEAT
"Sales Table".INIT;
"Sales Table"."Document Type" := "Sales Header Buffer"."Document Type";
"Sales Table"."No." := "Sales Header Buffer"."No.";
"Sales Table"."Sell-to Customer No." := "Sales Header Buffer"."Sell-to Customer No.";
"Sales Table".VALIDATE("Sales Table"."Document Date",TODAY);
"Sales Table".LOCKTABLE;
IF NOT("Sales Table".INSERT)
THEN BEGIN
"Sales Header Buffer"."Error":= TRUE;
"Sales Header Buffer".MODIFY(TRUE);
END
ELSE begin
message('Imported Successfully';)
END;
COMMIT;
UNTIL "Sales Header Buffer".NEXT = 0;
END;
any help on this please
0
Comments
-
You cannot do it in this way. If you are using NAV 5.0SP1, you can use the construction
if codeunit.run(myrecord) then begin //Ok end else begin //Error MESSAGE('%1',GETLASTERRORTEXT); end;
You need to insert the code into the codeunit OnRun trigger (or just calling some function from there). If there is any error in the CU, it will return false, if all is ok, it will return true and you can catch these and get the error text to save it somewhere when needed. Just do not forget that it will run as separate transaction...0 -
Hi,
i am using NAV 20090 -
Kine's suggestoin also works for NAV 2009Don't just take my word for it, test it yourself0
-
or just
IF NOT "Sales Table".INSERT(TRUE) then BEGIN
.....
When inserting with true - you tricker the insert trigger.0 -
If you don't use the Codeunit.RUN construction you will have a break on your loop if there is an error within the OnInsert trigger or the OnValidate trigger of a certain field. In that case you can't mark your record."Money is likewise the greatest chance and the greatest scourge of mankind."0
-
thank u all for your help,i got it solved.
i used the codeunit.run() and this was the best way i could achieve it.
thanks again :thumbsup: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