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

albertbuiguesalbertbuigues Member Posts: 7
edited 2020-12-11 in NAV Three Tier
I have to import orders from an XML that contains:
  • 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;
}

Answers

  • krikikriki Member, Moderator Posts: 9,115
    [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!


Sign In or Register to comment.