IF NOT "Sales Header".GET("Sales Header"."Document Type"::Order, "Sales Header"."No.") THEN BEGIN
"Sales Header".INIT;
"Sales Header"."Document Type" := "Sales Header"."Document Type"::Order;
"Sales Header"."No." := "Sales Header"."No.";
Customer.SETRANGE("No.", customer_nr_from_xml);
IF Customer.FIND('-') THEN BEGIN
"Sales Header"."Sell-to Customer No." := Customer."No.";
"Sales Header".VALIDATE("Sell-to Customer No.", Customer."No.");
END;
END;
IF NOT "Sales Line".GET("Sales Line"."Document Type"::Order, "Sales Line"."No.") THEN BEGIN
"Sales Line".INIT;
IF "Sales Line".FIND('+') THEN BEGIN
"Sales Line"."Document Type" := "Sales Line"."Document Type"::Order;
"Sales Line"."Document No." := "Sales Line"."Document No."
END;
Item.SETRANGE("No. 2", katalognr);
IF Item.FIND('-') THEN BEGIN
"Sales Line"."Document Type" := "Sales Header"."Document Type"::Order;
"Sales Line"."Document No." := "Sales Header"."No.";
"Sales Line".Type := "Sales Line".Type::Item;
"Sales Line"."No." := Item."No.";
"Sales Line"."Line No." := positionnr;
"Sales Line".VALIDATE("No.");
END;
positionnr := positionnr + 10000;
END;
Comments
NAV2017 / Version 10.0.16585
How have you structured your XML Port? Did you structure Sales Header as parent node and Sales Lines as child node? Which trigger are your placing your codes ?
No Problem!
In a late Night Session i was succesful, so my import is working fine now.
Nevertheless i think, my code is not as good as it should be...
Function "CreateSalesLine() : Code [10]
Function "CreateSalesHeader() : Code[10]
Using temporary instances of sales headers and sales lines could have been useful.
Validates are missing in sales lines
Not sure about the use of "Sales Line".SETFILTER("Quantity",menge);
Sales Line code could have been put into a function as well.
As Developer101 said, a lot of improvements are needed.
For example, on your sales line if the item does not exists, you still create a Sales Line, but it's not linked to anything. If that happens twice, you will get errors and your import no longer works and without a way for users to fix it.
I'm certain I can still learn a thing or two, but I'd start by making it like this: