Creating sales header ignore dimension code

galmok
Member Posts: 44
When I create orders in a dataport import, I use this to create sales headers:
SalesHeader.INIT;
SalesHeader."No.":='';
SalesHeader.VALIDATE("No.");
SalesHeader.VALIDATE("Document Type",SalesHeader."Document Type"::Order);
SalesHeader.VALIDATE("Sell-to Customer No.",impNo);
SalesHeader.VALIDATE("External Document No.",impExternalDocumentNumber);
SalesHeader.VALIDATE("Shortcut Dimension 1 Code",'SOMECODE');
SalesHeader.INSERT(TRUE);
impNo and impExternalDocumentNumber are set to the right values, but the Shortcut Dimension 1 Code is not inserted. I also don't get any error. The VALIDATE just silently fails. Everything else seems to work just fine. The sales header is created with the required information except for the Dimension code (which does exist).
I am obviously missing something, but what? :-)
SalesHeader.INIT;
SalesHeader."No.":='';
SalesHeader.VALIDATE("No.");
SalesHeader.VALIDATE("Document Type",SalesHeader."Document Type"::Order);
SalesHeader.VALIDATE("Sell-to Customer No.",impNo);
SalesHeader.VALIDATE("External Document No.",impExternalDocumentNumber);
SalesHeader.VALIDATE("Shortcut Dimension 1 Code",'SOMECODE');
SalesHeader.INSERT(TRUE);
impNo and impExternalDocumentNumber are set to the right values, but the Shortcut Dimension 1 Code is not inserted. I also don't get any error. The VALIDATE just silently fails. Everything else seems to work just fine. The sales header is created with the required information except for the Dimension code (which does exist).
I am obviously missing something, but what? :-)
0
Answers
-
To be as close as possible to manual data entering the correct insert procedure is this:
SalesHeader.INIT; SalesHeader.VALIDATE("Document Type",SalesHeader."Document Type"::Order); SalesHeader."No.":=''; SalesHeader.VALIDATE("No."); SalesHeader.INSERT(True); //Insert the record into table SalesHeader.VALIDATE("Sell-to Customer No.",impNo); SalesHeader.VALIDATE("External Document No.",impExternalDocumentNumber); SalesHeader.VALIDATE("Shortcut Dimension 1 Code",'SOMECODE'); SalesHeader.MODIFY(TRUE); //modify it
When the dimensions are processed, the header must be inserted into DB already, because the dimension entries must be created and connected to this record.0 -
Your code looks pretty standard and correct.
My thoughts would be to check the OnValidate trigger for the Dimension Code in the Sales Header. Maybe there was a modification to it that you have forgotten or don't know about.
Check the document dimension table. I usually see it the other way around, where the dimension is displayed on the header and is not in the document dimension table, but I suppose it could be this way.
Try putting a CONFIRM after the VALIDATE, CONFIRM('%1', TRUE, SalesHeader."Shortcut Dimension 1 Code"); See if it is coming back set correctly from the validate trigger.
Then put one after the insert. Maybe something in the insert trigger is changing the value.
Hope those help. Good luck.0 -
Thank you, kine. I already suspected that it didn't get the order of the fields quite right but just couldn't see the problem. Your suggestion worked just fine. :-)0
-
You are welcome. If the problem is solved, please, add [solved] prefix into your first post subject. Thanks.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