A logical problem i don't know how to resolve (code comments in spanish)

albertbuigues
Member Posts: 7
I have to import orders from an XML that contains:
The point is that some headers has the same customerNo and Order Date combination so I have to put in that case the lines into the same order.
This is my xmlport code: The filter doesn't seems to work but I don't know now another way to do it. CabeceraPedido is the header i'm importing or Lineas for lines. HeaderRec is the table (that i think has to contain the records already inserted).
xmlport 50002 "NZ0 Import Sales Orders XML"
{
Caption = 'Sales orders from XML', Comment = 'ESP = "Pedidos de venta desde XML"';
Direction = Import;
Format = Xml;
schema
{
textelement(PedidosManuales)
{
tableelement(CabeceraPedido; "NZ0 Aux. Sales Header")
{
fieldelement(Cliente; CabeceraPedido."Customer No.") { }
fieldelement(FechaPedido; CabeceraPedido."Order Date") { }
tableelement(Lineas; "NZ0 Aux. Sales Line")
{
LinkTable = CabeceraPedido;
LinkFields = "Document No." = field("Order No.");
fieldelement(Tipo; Lineas.Type) { }
fieldelement(Producto; Lineas."Item No.") { }
fieldelement(Cantidad; Lineas.Quantity) { }
trigger OnBeforeInsertRecord()
begin
// Filtro los registros ya introducidos que comparten cliente y fecha de cabecera con el del import que se está importando
// TODO: El filtrado no está funcionando
HeaderRec.SetFilter("Customer No.", '=%1', CabeceraPedido."Customer No.");
HeaderRec.SetFilter("Order Date", '=%1', CabeceraPedido."Order Date");
// Obtener todos los registros ya insertados con los filtros
HeaderRec.FindSet();
// Comprobar si la cabecera ya existe
if (HeaderRec.Count() = 1) THEN begin
Counter += 1;
Message(StrSubstNo('Encontrados ', Contador, ' registros.'));
end
else begin
// En caso de que no haya otro registro igual importa la linea
Lineas."Document No." := CabeceraPedido."Order No.";
Lineas."Document Type" := Lineas."Document Type"::Order;
Lineas."Line No." := Lineas."Line No." + 10000;
end;
end;
}
trigger OnBeforeInsertRecord()
begin
// Antes de introducir la cabecera
CabeceraPedido."Document Type" := CabeceraPedido."Document Type"::Order;
end;
}
}
}
var
HeaderRec: Record "NZ0 Aux. Sales Header";
Counter: Integer;
}
- Customer No && Order Date (Header)
- Line Type && Item No && Quantity (Line)
The point is that some headers has the same customerNo and Order Date combination so I have to put in that case the lines into the same order.
This is my xmlport code: The filter doesn't seems to work but I don't know now another way to do it. CabeceraPedido is the header i'm importing or Lineas for lines. HeaderRec is the table (that i think has to contain the records already inserted).
xmlport 50002 "NZ0 Import Sales Orders XML"
{
Caption = 'Sales orders from XML', Comment = 'ESP = "Pedidos de venta desde XML"';
Direction = Import;
Format = Xml;
schema
{
textelement(PedidosManuales)
{
tableelement(CabeceraPedido; "NZ0 Aux. Sales Header")
{
fieldelement(Cliente; CabeceraPedido."Customer No.") { }
fieldelement(FechaPedido; CabeceraPedido."Order Date") { }
tableelement(Lineas; "NZ0 Aux. Sales Line")
{
LinkTable = CabeceraPedido;
LinkFields = "Document No." = field("Order No.");
fieldelement(Tipo; Lineas.Type) { }
fieldelement(Producto; Lineas."Item No.") { }
fieldelement(Cantidad; Lineas.Quantity) { }
trigger OnBeforeInsertRecord()
begin
// Filtro los registros ya introducidos que comparten cliente y fecha de cabecera con el del import que se está importando
// TODO: El filtrado no está funcionando
HeaderRec.SetFilter("Customer No.", '=%1', CabeceraPedido."Customer No.");
HeaderRec.SetFilter("Order Date", '=%1', CabeceraPedido."Order Date");
// Obtener todos los registros ya insertados con los filtros
HeaderRec.FindSet();
// Comprobar si la cabecera ya existe
if (HeaderRec.Count() = 1) THEN begin
Counter += 1;
Message(StrSubstNo('Encontrados ', Contador, ' registros.'));
end
else begin
// En caso de que no haya otro registro igual importa la linea
Lineas."Document No." := CabeceraPedido."Order No.";
Lineas."Document Type" := Lineas."Document Type"::Order;
Lineas."Line No." := Lineas."Line No." + 10000;
end;
end;
}
trigger OnBeforeInsertRecord()
begin
// Antes de introducir la cabecera
CabeceraPedido."Document Type" := CabeceraPedido."Document Type"::Order;
end;
}
}
}
var
HeaderRec: Record "NZ0 Aux. Sales Header";
Counter: Integer;
}
0
Answers
-
[Topic moved from 'NAV Tips & Tricks' forum to 'NAV Three Tier' forum]
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!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