Options

How to import the sales/purchase lines to the Sales/purchase order page using code unit/Xmlport

RkpSaduRkpSadu Member Posts: 6
Want to import the Item number,Quantity,Unit Price in the Purchase line in purchase order page

Answers

  • Options
    SanderDkSanderDk Member Posts: 497
    What have you tryed so far?
    For help, do not use PM, use forum instead, perhaps other people have the same question, or better answers.
  • Options
    RkpSaduRkpSadu Member Posts: 6
    edited 2019-08-21
    Created Xml,Created Codeunit also.
    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;
  • Options
    ShaiHuludShaiHulud Member Posts: 228
    edited 2019-08-21
    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
  • Options
    RkpSaduRkpSadu Member Posts: 6
    Property Value
    Indentation 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>
  • Options
    RkpSaduRkpSadu Member Posts: 6
    xs6haynzrcj0.jpg
Sign In or Register to comment.