Importing orders from XML (exercise)

albertbuigues
Member Posts: 7
Hi all, I'm doing a practical exercise for my enterprise where i'm making my stages for my software programming studies and I have to import from an XML sales orders with their headers and lines. The XML only passes me the Customer No, the Order Date for the header and the sales line type, the item no and the quantity for lines. I have to pass them to a table i've created of "Auxiliar Orders". I make this on the prexmlport trigger:
trigger OnPreXmlPort()
begin
CabeceraPedido.Init();
CabeceraPedido."Document Type" := CabeceraPedido."Document Type"::Order;
CabeceraPedido.Insert(true);
Lineas.Init();
Lineas."Document No." := CabeceraPedido."Order No.";
Lineas."Document Type" := Lineas."Document Type"::Order;
Lineas."Line No." += 10000;
Lineas.Insert();
end;
Because some fields that are in the PK are not in the xml.
And I have this error.
"The record in table Aux. Sales Line already exists. Identification fields and values: Document Type='Order',Document No.='NS00032',Line No.='10000'"
I use a NS for the Order No and Document No fields. How can I solve this?
trigger OnPreXmlPort()
begin
CabeceraPedido.Init();
CabeceraPedido."Document Type" := CabeceraPedido."Document Type"::Order;
CabeceraPedido.Insert(true);
Lineas.Init();
Lineas."Document No." := CabeceraPedido."Order No.";
Lineas."Document Type" := Lineas."Document Type"::Order;
Lineas."Line No." += 10000;
Lineas.Insert();
end;
Because some fields that are in the PK are not in the xml.
And I have this error.
"The record in table Aux. Sales Line already exists. Identification fields and values: Document Type='Order',Document No.='NS00032',Line No.='10000'"
I use a NS for the Order No and Document No fields. How can I solve this?
0
Answers
-
My guess is that you have created the Lineas as a local variable instead of as a global. Thus everytime being reset and starting "Line No." from 0Don't just take my word for it, test it yourself0
-
This is wrong:Lineas."Line No." += 10000;
You need to create a global variable, i.e LineNo type IntegerLineNo += 10000 Lineas."Line No." := LineNo
0 -
@albertbuigues I will Suggest to make a new function for line number assignment with integer return. Do the Sorting on Primary Key and then Assign next line no to 10000.Thanks
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/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