Without knowing what your XMLPort looks like, and where exactly the error occurs, it's impossible to tell what the issue is.
However, the rest of your code has some issues as well:
You don't VALIDATE SalesHeader."Sell-to Customer No.", meaning a LOT of fields will not be filled in.
You use FINDSET on SalesLine to determine the last used "Line No.". That's not going to return you what you want. You must use FINDLAST
You don't MODIFY either the SalesHeader or SalesLine.
Additionally, I'm guessing all this could be moved to the XMLPort as it can do calculations/code. But again, without seeing your XMLPort (structure and code), not much else can be said about _why_ it's not working
Answers
codeunit is:
OnRun(VAR Rec : Record "Sales Header")
SalesHeader.RESET();
SalesLine.RESET();
CLEAR(LineNo);
LineNo:=0;
IF SalesHeader.GET(Rec."Document Type",Rec."No.") THEN BEGIN
SalesHeader."Sell-to Customer No.":=Rec."Sell-to Customer No.";
SalesLine.SETRANGE("Document No.",SalesHeader."No.");
IF SalesLine. FINDSET THEN
LineNo:=SalesLine."Line No."+10000
ELSE
LineNo:=10000;
CLEAR(InsertSalesLine);
InsertSalesLine.INIT;
InsertSalesLine.VALIDATE("Document Type",SalesHeader."Document Type");
InsertSalesLine.VALIDATE("Document No.",SalesHeader."No.");
InsertSalesLine.VALIDATE("Line No.",LineNo);
InsertSalesLine.INSERT(TRUE);
InsertSalesLine.VALIDATE(Type,InsertSalesLine.Type::Item);
SalesOrderXmlFile := 'C:\Multiple\NewSalesOrder.xml';
UPLOADINTOSTREAM('Import','',' Xml Files (*.txt)|*.txt',SalesOrderXmlFile,XmlStream);
IsImported :=XMLPORT.IMPORT(XMLPORT::ImportSalesLine,XmlStream); //error throwing here(False).
IF (IsImported = TRUE) THEN
MESSAGE('The import from XML is complete.')
ELSE
MESSAGE(GETLASTERRORTEXT);
END;
However, the rest of your code has some issues as well:
- You don't VALIDATE SalesHeader."Sell-to Customer No.", meaning a LOT of fields will not be filled in.
- You use FINDSET on SalesLine to determine the last used "Line No.". That's not going to return you what you want. You must use FINDLAST
- You don't MODIFY either the SalesHeader or SalesLine.
Additionally, I'm guessing all this could be moved to the XMLPort as it can do calculations/code. But again, without seeing your XMLPort (structure and code), not much else can be said about _why_ it's not workingIndentation 1
NodeName Line
NodeType Element
SourceType Table
SourceTable Sales Line
VariableName <Sales Line>
SourceTableView <Undefined>
ReqFilterHeading <>
ReqFilterHeadingML <>
CalcFields <Undefined>
ReqFilterFields <Undefined>
LinkTable Sales Header
LinkTableForceInsert <Yes>
LinkFields Document No.=FIELD(No.)
Temporary <No>
AutoSave <Yes>
AutoUpdate <No>
AutoReplace <No>
Width <0>
NamespacePrefix <Undefined>
MinOccurs <Once>
MaxOccurs <Unbounded>