Options

validate itemno in sales line,another field will be emptied?

julkifli33julkifli33 Member Posts: 1,073
hi all
i have created function to import from txt file to NAV
i add i more field in sales line table, named Imported (boolean)
i want everything imported, this imported field will be TRUE

this is my code
     //*********** SALES LINE ************
        SL2.RESET;
        SL2.SETRANGE(SL2."Document Type",DocType);
        SL2.SETRANGE(SL2."Document No.",DocNo);
        IF SL2.FIND('+') THEN
        BEGIN
          LineNo := SL2."Line No." + 10000;
        END
        ELSE
        BEGIN
          LineNo := 10000;
        END;

        SL.RESET;
        SL."Document Type" := DocType;
        SL."Document No." := DocNo;
        SL."Line No." := LineNo;
        SL.Type := SL.Type::Item;

        //Item No.	
        PosCode:=STRPOS(vString,';');
        SL.VALIDATE(SL."No.",FORMAT(COPYSTR(vString,1,PosCode-1)));
        vString:=DELSTR(vString,1,PosCode);

        SL.Imported := TRUE;
        SL.INSERT(TRUE);

my question is....
why imported field only last row only for each document
for example i have 3 documents
document 1 --> 3 lines
document 2 --> 1 line
document 3 --> 2 lines

imported as true only last line only for each document
here i as my attacment
«1

Comments

  • Options
    SavatageSavatage Member Posts: 7,142
    I don't like your code that much.

    Why not just map the fields at the first point when you get a line #?
    What's your thinking on the use of SL2?
    2 resets?

    Simplify.

    //*********** SALES LINE ************
            SL2.RESET;
            SL2.SETRANGE(SL2."Document Type",DocType);
            SL2.SETRANGE(SL2."Document No.",DocNo);
            IF SL2.FIND('+') THEN
            BEGIN
              LineNo := SL2."Line No." + 10000;
    >>map all fields here
    >>map all fields here       
    END
    
  • Options
    kapamaroukapamarou Member Posts: 1,152
    I agree with Harry.

    Also try to provide some more details. Is this a dataport? Where is the code located? Are there any more lines of code?
  • Options
    julkifli33julkifli33 Member Posts: 1,073
    Savatage wrote:
    I don't like your code that much.

    Why not just map the fields at the first point when you get a line #?
    What's your thinking on the use of SL2?
    2 resets?

    Simplify.

    //*********** SALES LINE ************
            SL2.RESET;
            SL2.SETRANGE(SL2."Document Type",DocType);
            SL2.SETRANGE(SL2."Document No.",DocNo);
            IF SL2.FIND('+') THEN
            BEGIN
              LineNo := SL2."Line No." + 10000;
    >>map all fields here
    >>map all fields here       
    END
    

    Hi Savatage,
    i use SL2, just to get last line no
    so the main SL is SL
  • Options
    julkifli33julkifli33 Member Posts: 1,073
    kapamarou wrote:
    I agree with Harry.

    Also try to provide some more details. Is this a dataport? Where is the code located? Are there any more lines of code?
    i'm using codeunit
    i change the code become like this
            IF (SH."Document Type" <> TempDocType) AND (SH."No." <> TempDocNo) THEN
            SH.INSERT(TRUE);
    
            TempDocType := SH."Document Type";
            TempDocNo := SH."No.";
    
         //*********** SALES LINE ************
            SL.RESET;
            SL.SETRANGE(SL."Document Type",DocType);
            SL.SETRANGE(SL."Document No.",DocNo);
            IF SL.FIND('+') THEN
            BEGIN
              SL."Document Type" := DocType;
              SL."Document No." := DocNo;
              SL."Line No." := SL."Line No." + 10000;
              SL.Type := SL.Type::Item;
              //Item No.	
              PosCode:=STRPOS(vString,';');
              SL.VALIDATE(SL."No.",FORMAT(COPYSTR(vString,1,PosCode-1)));
              vString:=DELSTR(vString,1,PosCode);
              SL.Description := 'Test';
              SL.Imported := TRUE;
              SL.INSERT(TRUE);
            END
            ELSE
            BEGIN
              SL."Document Type" := DocType;
              SL."Document No." := DocNo;
              SL."Line No." := 10000;
              SL.Type := SL.Type::Item;
              //Item No.	
              PosCode:=STRPOS(vString,';');
              SL.VALIDATE(SL."No.",FORMAT(COPYSTR(vString,1,PosCode-1)));
              vString:=DELSTR(vString,1,PosCode);
              SL.Description := 'Test';
              SL.Imported := TRUE;
              SL.INSERT(TRUE);
    
            END;
    
    

    but still the same result
  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,503
    Try this
            IF (SH."Document Type" <> TempDocType) AND (SH."No." <> TempDocNo) THEN
            SH.INSERT(TRUE);
    
            TempDocType := SH."Document Type";
            TempDocNo := SH."No.";
    
         //*********** SALES LINE ************
            SL.RESET;
            SL.SETRANGE(SL."Document Type",DocType);
            SL.SETRANGE(SL."Document No.",DocNo);
            IF SL.FIND('+') THEN
            BEGIN
              SL."Document Type" := DocType;
              SL."Document No." := DocNo;
              SL."Line No." := SL."Line No." + 10000;
              SL.Type := SL.Type::Item;
              //Item No.   
              PosCode:=STRPOS(vString,';');
              SL.VALIDATE(SL."No.",FORMAT(COPYSTR(vString,1,PosCode-1)));
              vString:=DELSTR(vString,1,PosCode);
              SL.Description := 'Test';
              SL.INSERT(TRUE);
              SL.Imported := TRUE;
              SL.MODIFY;
            END
            ELSE
            BEGIN
              SL."Document Type" := DocType;
              SL."Document No." := DocNo;
              SL."Line No." := 10000;
              SL.Type := SL.Type::Item;
              //Item No.   
              PosCode:=STRPOS(vString,';');
              SL.VALIDATE(SL."No.",FORMAT(COPYSTR(vString,1,PosCode-1)));
              vString:=DELSTR(vString,1,PosCode);
              SL.Description := 'Test';
              SL.INSERT(TRUE);
              SL.Imported := TRUE;
              SL.MODIFY;
            END;
    
  • Options
    julkifli33julkifli33 Member Posts: 1,073
    Hi Mohana,
    i change my code
    and it still the same result
    only last line will tick imported as true
    what happened with my code
    :-k :-k
    this is my full code
    GLSetup.GET;
    SFile.TEXTMODE(TRUE);
    SFile.WRITEMODE(FALSE);
    SFile.OPEN('D:\Data\Test.txt');
      REPEAT 
        SFile.READ(vString);
        //Transaction Type
        PosCode:=STRPOS(vString,';');
        vStringTransaction := FORMAT(COPYSTR(vString,1,PosCode-1));
        vString:=DELSTR(vString,1,PosCode);
    
        IF vStringTransaction = 'Sale' THEN
          BEGIN
         //********* SALES HEADER ************
            //SH Document Type
            PosCode:=STRPOS(vString,';');
            IF FORMAT(COPYSTR(vString,1,PosCode-1)) = 'Order' THEN
            SH."Document Type" := SH."Document Type"::Order;
            IF FORMAT(COPYSTR(vString,1,PosCode-1)) = 'Invoice' THEN
            SH."Document Type" := SH."Document Type"::Invoice;
            IF FORMAT(COPYSTR(vString,1,PosCode-1)) = 'Return Order' THEN
            SH."Document Type" := SH."Document Type"::"Return Order";
            IF FORMAT(COPYSTR(vString,1,PosCode-1)) = 'Credit Memo' THEN
            SH."Document Type" := SH."Document Type"::"Credit Memo";
            vString:=DELSTR(vString,1,PosCode);
    
            DocType := SH."Document Type";
    
            //SH No. & SH Sell-to Customer No
            PosCode:=STRPOS(vString,';');
            SH."Sell-to Customer No." := FORMAT(COPYSTR(vString,1,PosCode-1));
            vString:=DELSTR(vString,1,PosCode);
    
            PosCode:=STRPOS(vString,';');
            SH."No." := FORMAT(COPYSTR(vString,1,PosCode-1));
            vString:=DELSTR(vString,1,PosCode);
            SH.VALIDATE(SH."No.");
            SH.InitRecord;
            SH.SetHideValidationDialog(TRUE);
            SH.VALIDATE(SH."Sell-to Customer No.");
    
            DocNo := SH."No.";
            //External Doc No.
            PosCode:=STRPOS(vString,';');
            SH."External Document No." := FORMAT(COPYSTR(vString,1,PosCode-1));
            vString:=DELSTR(vString,1,PosCode);
    
            //Posting Date
            PosCode:=STRPOS(vString,';');
            PostingDateText := FORMAT(COPYSTR(vString,1,PosCode-1));
            SH."Posting Date" := ConvertPostingDate(PostingDateText);
            vString:=DELSTR(vString,1,PosCode);
    
            //Payment Terms Code	
            PosCode:=STRPOS(vString,';');
            SH."Payment Terms Code" := FORMAT(COPYSTR(vString,1,PosCode-1));
            vString:=DELSTR(vString,1,PosCode);
    
            //Due Date	
            PosCode:=STRPOS(vString,';');
            SalesDueDateText := FORMAT(COPYSTR(vString,1,PosCode-1));
            SH."Due Date" := ConvertSalesDueDate(SalesDueDateText);
            vString:=DELSTR(vString,1,PosCode);
    
            //Vendor / Customer Posting Group	
            PosCode:=STRPOS(vString,';');
            SH."Customer Posting Group" := FORMAT(COPYSTR(vString,1,PosCode-1));
            vString:=DELSTR(vString,1,PosCode);
    
            //Currency Code	
            PosCode:=STRPOS(vString,';');
            SH."Currency Code" := FORMAT(COPYSTR(vString,1,PosCode-1));
            SH.VALIDATE(SH."Currency Code");
            vString:=DELSTR(vString,1,PosCode);
    
            //Purchaser / Salesperson Code
            PosCode:=STRPOS(vString,';');
            SH."Salesperson Code" := FORMAT(COPYSTR(vString,1,PosCode-1));
            vString:=DELSTR(vString,1,PosCode);
    
            //	Document Date	
            PosCode:=STRPOS(vString,';');
            SalesDocumentDateText := FORMAT(COPYSTR(vString,1,PosCode-1));
            SH."Document Date" := ConvertSalesDocumentDate(SalesDocumentDateText);
            vString:=DELSTR(vString,1,PosCode);
    
            //Payment Method
            PosCode:=STRPOS(vString,';');
            SH."Payment Method Code" := FORMAT(COPYSTR(vString,1,PosCode-1));
            vString:=DELSTR(vString,1,PosCode);
    
            SH.Imported := TRUE;
    
            IF (SH."Document Type" <> TempDocType) AND (SH."No." <> TempDocNo) THEN
            SH.INSERT(TRUE);
    
            TempDocType := SH."Document Type";
            TempDocNo := SH."No.";
      //*********** SALES LINE ************
            IF (SH."Document Type" <> TempDocType) AND (SH."No." <> TempDocNo) THEN
            SH.INSERT(TRUE);
    
            TempDocType := SH."Document Type";
            TempDocNo := SH."No.";
    
         //*********** SALES LINE ************
            SL.RESET;
            SL.SETRANGE(SL."Document Type",DocType);
            SL.SETRANGE(SL."Document No.",DocNo);
            IF SL.FIND('+') THEN
            BEGIN
              SL."Document Type" := DocType;
              SL."Document No." := DocNo;
              SL."Line No." := SL."Line No." + 10000;
              SL.Type := SL.Type::Item;
              //Item No.   
              PosCode:=STRPOS(vString,';');
              SL.VALIDATE(SL."No.",FORMAT(COPYSTR(vString,1,PosCode-1)));
              vString:=DELSTR(vString,1,PosCode);
              SL.Description := 'Test';
              SL.INSERT(TRUE);
              SL.Imported := TRUE;
              SL.MODIFY;
            END
            ELSE
            BEGIN
              SL."Document Type" := DocType;
              SL."Document No." := DocNo;
              SL."Line No." := 10000;
              SL.Type := SL.Type::Item;
              //Item No.   
              PosCode:=STRPOS(vString,';');
              SL.VALIDATE(SL."No.",FORMAT(COPYSTR(vString,1,PosCode-1)));
              vString:=DELSTR(vString,1,PosCode);
              SL.Description := 'Test';
              SL.INSERT(TRUE);
              SL.Imported := TRUE;
              SL.MODIFY;
            END;
          END;
      UNTIL
    SFile.POS = SFile.LEN;
    MESSAGE('Import Done');
    
  • Options
    dansdans Member Posts: 148
    Change your code to this
    SL.RESET;
    SL.SETRANGE(SL."Document Type",DocType);
    SL.SETRANGE(SL."Document No.",DocNo);
    IF SL.FINDLAST THEN
      LineNo := SL."Line No." + 10000
    ELSE
      LineNo := 10000;
    
    SL.RESET;
    SL.INIT;          
    SL."Document Type" := DocType;
    SL."Document No." := DocNo;
    SL."Line No." := LineNo;
    SL.Type := SL.Type::Item;
    //Item No.   
    PosCode:=STRPOS(vString,';');
    SL.VALIDATE(SL."No.",FORMAT(COPYSTR(vString,1,PosCode-1)));
    vString:=DELSTR(vString,1,PosCode);
    SL.Description := 'Test';
    SL.Imported := TRUE;
    SL.INSERT(TRUE);
    

    LineNo is an integer variable. The SL filter on your code messed up the record reference.
    Microsoft Certified IT Professional for Microsoft Dynamics NAV

    Just a happy frood who knows where his towel is
  • Options
    julkifli33julkifli33 Member Posts: 1,073
    dans wrote:
    Change your code to this
    SL.RESET;
    SL.SETRANGE(SL."Document Type",DocType);
    SL.SETRANGE(SL."Document No.",DocNo);
    IF SL.FINDLAST THEN
      LineNo := SL."Line No." + 10000
    ELSE
      LineNo := 10000;
    
    SL.RESET;
    SL.INIT;          
    SL."Document Type" := DocType;
    SL."Document No." := DocNo;
    SL."Line No." := LineNo;
    SL.Type := SL.Type::Item;
    //Item No.   
    PosCode:=STRPOS(vString,';');
    SL.VALIDATE(SL."No.",FORMAT(COPYSTR(vString,1,PosCode-1)));
    vString:=DELSTR(vString,1,PosCode);
    SL.Description := 'Test';
    SL.Imported := TRUE;
    SL.INSERT(TRUE);
    

    LineNo is an integer variable. The SL filter on your code messed up the record reference.

    i use the same as you give me
    but still the same
    only last line for every document will updated

    here is the result in my attachment
  • Options
    dansdans Member Posts: 148
    could you show your full code after you modified it ?
    Microsoft Certified IT Professional for Microsoft Dynamics NAV

    Just a happy frood who knows where his towel is
  • Options
    julkifli33julkifli33 Member Posts: 1,073
    this is my full code
    i import from txt file
    sales header no problem
    but sales line have a problem
    [b]ImportData()[/b]
    
    GLSetup.GET;
    SFile.TEXTMODE(TRUE);
    SFile.WRITEMODE(FALSE);
    SFile.OPEN('D:\Data\Test.txt');
      REPEAT 
        SFile.READ(vString);
        //Transaction Type
        PosCode:=STRPOS(vString,';');
        vStringTransaction := FORMAT(COPYSTR(vString,1,PosCode-1));
        vString:=DELSTR(vString,1,PosCode);
    
        IF vStringTransaction = 'Sale' THEN
          BEGIN
         //********* SALES HEADER ************
            //SH Document Type
            PosCode:=STRPOS(vString,';');
            IF FORMAT(COPYSTR(vString,1,PosCode-1)) = 'Order' THEN
            SH."Document Type" := SH."Document Type"::Order;
            IF FORMAT(COPYSTR(vString,1,PosCode-1)) = 'Invoice' THEN
            SH."Document Type" := SH."Document Type"::Invoice;
            IF FORMAT(COPYSTR(vString,1,PosCode-1)) = 'Return Order' THEN
            SH."Document Type" := SH."Document Type"::"Return Order";
            IF FORMAT(COPYSTR(vString,1,PosCode-1)) = 'Credit Memo' THEN
            SH."Document Type" := SH."Document Type"::"Credit Memo";
            vString:=DELSTR(vString,1,PosCode);
    
            DocType := SH."Document Type";
    
            //SH No. & SH Sell-to Customer No
            PosCode:=STRPOS(vString,';');
            SH."Sell-to Customer No." := FORMAT(COPYSTR(vString,1,PosCode-1));
            vString:=DELSTR(vString,1,PosCode);
    
            PosCode:=STRPOS(vString,';');
            SH."No." := FORMAT(COPYSTR(vString,1,PosCode-1));
            vString:=DELSTR(vString,1,PosCode);
            SH.VALIDATE(SH."No.");
            SH.InitRecord;
            SH.SetHideValidationDialog(TRUE);
            SH.VALIDATE(SH."Sell-to Customer No.");
    
            DocNo := SH."No.";
            //External Doc No.
            PosCode:=STRPOS(vString,';');
            SH."External Document No." := FORMAT(COPYSTR(vString,1,PosCode-1));
            vString:=DELSTR(vString,1,PosCode);
    
            //Posting Date
            PosCode:=STRPOS(vString,';');
            PostingDateText := FORMAT(COPYSTR(vString,1,PosCode-1));
            SH."Posting Date" := ConvertPostingDate(PostingDateText);
            vString:=DELSTR(vString,1,PosCode);
    
            //Payment Terms Code	
            PosCode:=STRPOS(vString,';');
            SH."Payment Terms Code" := FORMAT(COPYSTR(vString,1,PosCode-1));
            vString:=DELSTR(vString,1,PosCode);
    
            //Due Date	
            PosCode:=STRPOS(vString,';');
            SalesDueDateText := FORMAT(COPYSTR(vString,1,PosCode-1));
            SH."Due Date" := ConvertSalesDueDate(SalesDueDateText);
            vString:=DELSTR(vString,1,PosCode);
    
            //Vendor / Customer Posting Group	
            PosCode:=STRPOS(vString,';');
            SH."Customer Posting Group" := FORMAT(COPYSTR(vString,1,PosCode-1));
            vString:=DELSTR(vString,1,PosCode);
    
            //Currency Code	
            PosCode:=STRPOS(vString,';');
            SH."Currency Code" := FORMAT(COPYSTR(vString,1,PosCode-1));
            SH.VALIDATE(SH."Currency Code");
            vString:=DELSTR(vString,1,PosCode);
    
            //Purchaser / Salesperson Code
            PosCode:=STRPOS(vString,';');
            SH."Salesperson Code" := FORMAT(COPYSTR(vString,1,PosCode-1));
            vString:=DELSTR(vString,1,PosCode);
    
            //	Document Date	
            PosCode:=STRPOS(vString,';');
            SalesDocumentDateText := FORMAT(COPYSTR(vString,1,PosCode-1));
            SH."Document Date" := ConvertSalesDocumentDate(SalesDocumentDateText);
            vString:=DELSTR(vString,1,PosCode);
    
            //Payment Method
            PosCode:=STRPOS(vString,';');
            SH."Payment Method Code" := FORMAT(COPYSTR(vString,1,PosCode-1));
            vString:=DELSTR(vString,1,PosCode);
    
            SH.Imported := TRUE;
    
            IF (SH."Document Type" <> TempDocType) AND (SH."No." <> TempDocNo) THEN
            BEGIN
              SH.INSERT(TRUE);
            END;
            TempDocType := SH."Document Type";
            TempDocNo := SH."No.";
    
         //*********** SALES LINE ************
          SL.RESET;
          SL.SETRANGE(SL."Document Type",DocType);
          SL.SETRANGE(SL."Document No.",DocNo);
          IF SL.FIND('+') THEN
            LineNo := SL."Line No." + 10000
          ELSE
            LineNo := 10000;
    
          SL.RESET;          
          SL."Document Type" := DocType;
          SL."Document No." := DocNo;
          SL."Line No." := LineNo;
          SL.Type := SL.Type::Item;
          //Item No.   
          PosCode:=STRPOS(vString,';');
          SL.VALIDATE(SL."No.",FORMAT(COPYSTR(vString,1,PosCode-1)));
          vString:=DELSTR(vString,1,PosCode);
          SL.Description := 'Test';
          SL.Imported := TRUE;
          SL.INSERT(TRUE);
    
          END;
      UNTIL
    SFile.POS = SFile.LEN;
    MESSAGE('Import Done');
    
  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,503
    Is there any where else you are modifying the Sales Line imported field?

    Like in Sales header field validations?

    why because you are validating all sales header fields for second time but not inserting if it is same doctype and docno..

    Please check..
  • Options
    dansdans Member Posts: 148
    Check the sales line and sales header table to see if there is any trigger / validation that set the Imported value to FALSE
    Microsoft Certified IT Professional for Microsoft Dynamics NAV

    Just a happy frood who knows where his towel is
  • Options
    julkifli33julkifli33 Member Posts: 1,073
    Is there any where else you are modifying the Sales Line imported field?

    Like in Sales header field validations?

    why because you are validating all sales header fields for second time but not inserting if it is same doctype and docno..

    Please check..

    there is no other code
    this is single and independent codeunit
    i trigger it by hit run button from this codeunit directly
  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,503
    I didnt mean in your codeunit..

    I mean in Sales Headder table onvalidate trigger's of all fields..
  • Options
    julkifli33julkifli33 Member Posts: 1,073
    I didnt mean in your codeunit..

    I mean in Sales Headder table onvalidate trigger's of all fields..
    no additional customization for table
    only add new fields
  • Options
    dansdans Member Posts: 148
    did you also import the first 2 lines using the same code ? were the first 2 lines already existed before you did the import ?
    Looking at your screenshot, the first 2 lines do not have 'test' as description.

    check also your sales header table to see if there is any validation that refresh the sales line.
    Microsoft Certified IT Professional for Microsoft Dynamics NAV

    Just a happy frood who knows where his towel is
  • Options
    julkifli33julkifli33 Member Posts: 1,073
    dans wrote:
    did you also import the first 2 lines using the same code ? were the first 2 lines already existed before you did the import ?
    Looking at your screenshot, the first 2 lines do not have 'test' as description.

    check also your sales header table to see if there is any validation that refresh the sales line.

    that's it...
    these 5 records are inserted from my code
    take a look from item no, this one inserted from txt file
    i think this one is because validation
    i think the is not related with sales header
    because first i insert header...... after that sales line, how come it come back to sales header
  • Options
    julkifli33julkifli33 Member Posts: 1,073
    i tried using message to catch the value every time sales line inserted
    all correct... but when i open the table
    like this
    weird
  • Options
    BernardJBernardJ Member Posts: 57
    I guess this is because the function RecreateSalesLines in the sales header is called from a validate on the header somehow. Only the last inserted sales line will stay intact that way. Try this:
    [b]ImportData()[/b]
    
    GLSetup.GET;
    SFile.TEXTMODE(TRUE);
    SFile.WRITEMODE(FALSE);
    SFile.OPEN('D:\Data\Test.txt');
      REPEAT 
        SFile.READ(vString);
        //Transaction Type
        PosCode:=STRPOS(vString,';');
        vStringTransaction := FORMAT(COPYSTR(vString,1,PosCode-1));
        vString:=DELSTR(vString,1,PosCode);
    
        IF vStringTransaction = 'Sale' THEN
          BEGIN
         //********* SALES HEADER ************
            //SH Document Type
            PosCode:=STRPOS(vString,';');
            IF FORMAT(COPYSTR(vString,1,PosCode-1)) = 'Order' THEN
            SH."Document Type" := SH."Document Type"::Order;
            IF FORMAT(COPYSTR(vString,1,PosCode-1)) = 'Invoice' THEN
            SH."Document Type" := SH."Document Type"::Invoice;
            IF FORMAT(COPYSTR(vString,1,PosCode-1)) = 'Return Order' THEN
            SH."Document Type" := SH."Document Type"::"Return Order";
            IF FORMAT(COPYSTR(vString,1,PosCode-1)) = 'Credit Memo' THEN
            SH."Document Type" := SH."Document Type"::"Credit Memo";
            vString:=DELSTR(vString,1,PosCode);
    
            DocType := SH."Document Type";
    
            //SH No. & SH Sell-to Customer No
            PosCode:=STRPOS(vString,';');
            SH."Sell-to Customer No." := FORMAT(COPYSTR(vString,1,PosCode-1));
            vString:=DELSTR(vString,1,PosCode);
    
            PosCode:=STRPOS(vString,';');
            SH."No." := FORMAT(COPYSTR(vString,1,PosCode-1));
    
            IF (SH."Document Type" <> TempDocType) AND (SH."No." <> TempDocNo) THEN
            BEGIN
    
              vString:=DELSTR(vString,1,PosCode);
              SH.VALIDATE(SH."No.");
              SH.InitRecord;
              SH.SetHideValidationDialog(TRUE);
              SH.VALIDATE(SH."Sell-to Customer No.");
    
              DocNo := SH."No.";
              //External Doc No.
              PosCode:=STRPOS(vString,';');
              SH."External Document No." := FORMAT(COPYSTR(vString,1,PosCode-1));
              vString:=DELSTR(vString,1,PosCode);
    
              //Posting Date
              PosCode:=STRPOS(vString,';');
              PostingDateText := FORMAT(COPYSTR(vString,1,PosCode-1));
              SH."Posting Date" := ConvertPostingDate(PostingDateText);
              vString:=DELSTR(vString,1,PosCode);
    
              //Payment Terms Code   
              PosCode:=STRPOS(vString,';');
              SH."Payment Terms Code" := FORMAT(COPYSTR(vString,1,PosCode-1));
              vString:=DELSTR(vString,1,PosCode);
    
              //Due Date   
              PosCode:=STRPOS(vString,';');
              SalesDueDateText := FORMAT(COPYSTR(vString,1,PosCode-1));
              SH."Due Date" := ConvertSalesDueDate(SalesDueDateText);
              vString:=DELSTR(vString,1,PosCode);
    
              //Vendor / Customer Posting Group   
              PosCode:=STRPOS(vString,';');
              SH."Customer Posting Group" := FORMAT(COPYSTR(vString,1,PosCode-1));
              vString:=DELSTR(vString,1,PosCode);
    
              //Currency Code   
              PosCode:=STRPOS(vString,';');
              SH."Currency Code" := FORMAT(COPYSTR(vString,1,PosCode-1));
              SH.VALIDATE(SH."Currency Code");
              vString:=DELSTR(vString,1,PosCode);
    
              //Purchaser / Salesperson Code
              PosCode:=STRPOS(vString,';');
              SH."Salesperson Code" := FORMAT(COPYSTR(vString,1,PosCode-1));
              vString:=DELSTR(vString,1,PosCode);
    
              //   Document Date   
              PosCode:=STRPOS(vString,';');
              SalesDocumentDateText := FORMAT(COPYSTR(vString,1,PosCode-1));
              SH."Document Date" := ConvertSalesDocumentDate(SalesDocumentDateText);
              vString:=DELSTR(vString,1,PosCode);
    
              //Payment Method
              PosCode:=STRPOS(vString,';');
              SH."Payment Method Code" := FORMAT(COPYSTR(vString,1,PosCode-1));
              vString:=DELSTR(vString,1,PosCode);
    
              SH.Imported := TRUE;
    
              SH.INSERT(TRUE);
            END;
            TempDocType := SH."Document Type";
            TempDocNo := SH."No.";
    
         //*********** SALES LINE ************
          SL.RESET;
          SL.SETRANGE(SL."Document Type",DocType);
          SL.SETRANGE(SL."Document No.",DocNo);
          IF SL.FIND('+') THEN
            LineNo := SL."Line No." + 10000
          ELSE
            LineNo := 10000;
    
          SL.RESET;          
          SL."Document Type" := DocType;
          SL."Document No." := DocNo;
          SL."Line No." := LineNo;
          SL.Type := SL.Type::Item;
          //Item No.   
          PosCode:=STRPOS(vString,';');
          SL.VALIDATE(SL."No.",FORMAT(COPYSTR(vString,1,PosCode-1)));
          vString:=DELSTR(vString,1,PosCode);
          SL.Description := 'Test';
          SL.Imported := TRUE;
          SL.INSERT(TRUE);
    
          END;
      UNTIL
    SFile.POS = SFile.LEN;
    MESSAGE('Import Done');
    
  • Options
    julkifli33julkifli33 Member Posts: 1,073
    BernardJ wrote:
    I guess this is because the function RecreateSalesLines in the sales header is called from a validate on the header somehow. Only the last inserted sales line will stay intact that way. Try this:
    [b]ImportData()[/b]
    
    GLSetup.GET;
    SFile.TEXTMODE(TRUE);
    SFile.WRITEMODE(FALSE);
    SFile.OPEN('D:\Data\Test.txt');
      REPEAT 
        SFile.READ(vString);
        //Transaction Type
        PosCode:=STRPOS(vString,';');
        vStringTransaction := FORMAT(COPYSTR(vString,1,PosCode-1));
        vString:=DELSTR(vString,1,PosCode);
    
        IF vStringTransaction = 'Sale' THEN
          BEGIN
         //********* SALES HEADER ************
            //SH Document Type
            PosCode:=STRPOS(vString,';');
            IF FORMAT(COPYSTR(vString,1,PosCode-1)) = 'Order' THEN
            SH."Document Type" := SH."Document Type"::Order;
            IF FORMAT(COPYSTR(vString,1,PosCode-1)) = 'Invoice' THEN
            SH."Document Type" := SH."Document Type"::Invoice;
            IF FORMAT(COPYSTR(vString,1,PosCode-1)) = 'Return Order' THEN
            SH."Document Type" := SH."Document Type"::"Return Order";
            IF FORMAT(COPYSTR(vString,1,PosCode-1)) = 'Credit Memo' THEN
            SH."Document Type" := SH."Document Type"::"Credit Memo";
            vString:=DELSTR(vString,1,PosCode);
    
            DocType := SH."Document Type";
    
            //SH No. & SH Sell-to Customer No
            PosCode:=STRPOS(vString,';');
            SH."Sell-to Customer No." := FORMAT(COPYSTR(vString,1,PosCode-1));
            vString:=DELSTR(vString,1,PosCode);
    
            PosCode:=STRPOS(vString,';');
            SH."No." := FORMAT(COPYSTR(vString,1,PosCode-1));
    
            IF (SH."Document Type" <> TempDocType) AND (SH."No." <> TempDocNo) THEN
            BEGIN
    
              vString:=DELSTR(vString,1,PosCode);
              SH.VALIDATE(SH."No.");
              SH.InitRecord;
              SH.SetHideValidationDialog(TRUE);
              SH.VALIDATE(SH."Sell-to Customer No.");
    
              DocNo := SH."No.";
              //External Doc No.
              PosCode:=STRPOS(vString,';');
              SH."External Document No." := FORMAT(COPYSTR(vString,1,PosCode-1));
              vString:=DELSTR(vString,1,PosCode);
    
              //Posting Date
              PosCode:=STRPOS(vString,';');
              PostingDateText := FORMAT(COPYSTR(vString,1,PosCode-1));
              SH."Posting Date" := ConvertPostingDate(PostingDateText);
              vString:=DELSTR(vString,1,PosCode);
    
              //Payment Terms Code   
              PosCode:=STRPOS(vString,';');
              SH."Payment Terms Code" := FORMAT(COPYSTR(vString,1,PosCode-1));
              vString:=DELSTR(vString,1,PosCode);
    
              //Due Date   
              PosCode:=STRPOS(vString,';');
              SalesDueDateText := FORMAT(COPYSTR(vString,1,PosCode-1));
              SH."Due Date" := ConvertSalesDueDate(SalesDueDateText);
              vString:=DELSTR(vString,1,PosCode);
    
              //Vendor / Customer Posting Group   
              PosCode:=STRPOS(vString,';');
              SH."Customer Posting Group" := FORMAT(COPYSTR(vString,1,PosCode-1));
              vString:=DELSTR(vString,1,PosCode);
    
              //Currency Code   
              PosCode:=STRPOS(vString,';');
              SH."Currency Code" := FORMAT(COPYSTR(vString,1,PosCode-1));
              SH.VALIDATE(SH."Currency Code");
              vString:=DELSTR(vString,1,PosCode);
    
              //Purchaser / Salesperson Code
              PosCode:=STRPOS(vString,';');
              SH."Salesperson Code" := FORMAT(COPYSTR(vString,1,PosCode-1));
              vString:=DELSTR(vString,1,PosCode);
    
              //   Document Date   
              PosCode:=STRPOS(vString,';');
              SalesDocumentDateText := FORMAT(COPYSTR(vString,1,PosCode-1));
              SH."Document Date" := ConvertSalesDocumentDate(SalesDocumentDateText);
              vString:=DELSTR(vString,1,PosCode);
    
              //Payment Method
              PosCode:=STRPOS(vString,';');
              SH."Payment Method Code" := FORMAT(COPYSTR(vString,1,PosCode-1));
              vString:=DELSTR(vString,1,PosCode);
    
              SH.Imported := TRUE;
    
              SH.INSERT(TRUE);
            END;
            TempDocType := SH."Document Type";
            TempDocNo := SH."No.";
    
         //*********** SALES LINE ************
          SL.RESET;
          SL.SETRANGE(SL."Document Type",DocType);
          SL.SETRANGE(SL."Document No.",DocNo);
          IF SL.FIND('+') THEN
            LineNo := SL."Line No." + 10000
          ELSE
            LineNo := 10000;
    
          SL.RESET;          
          SL."Document Type" := DocType;
          SL."Document No." := DocNo;
          SL."Line No." := LineNo;
          SL.Type := SL.Type::Item;
          //Item No.   
          PosCode:=STRPOS(vString,';');
          SL.VALIDATE(SL."No.",FORMAT(COPYSTR(vString,1,PosCode-1)));
          vString:=DELSTR(vString,1,PosCode);
          SL.Description := 'Test';
          SL.Imported := TRUE;
          SL.INSERT(TRUE);
    
          END;
      UNTIL
    SFile.POS = SFile.LEN;
    MESSAGE('Import Done');
    

    Hi Bernard,
    i tried your code
    but the result still the same :(
  • Options
    SavatageSavatage Member Posts: 7,142
    There must be something else going on that we don't see.
    Change the line description before running to something else to make sure that code is working. Because if it's inserting the description it should mark imported as well. Also do you get the same results if you sl.insert as opposed to sl.insert(true)?
  • Options
    julkifli33julkifli33 Member Posts: 1,073
    Savatage wrote:
    There must be something else going on that we don't see.
    Change the line description before running to something else to make sure that code is working. Because if it's inserting the description it should mark imported as well. Also do you get the same results if you sl.insert as opposed to sl.insert(true)?

    when i catch the code using message, it's correct
    every description would be 'Test'
    but the result is not....
    i tried sl.insert and sl.insert(true) already...
    i think this one is because validation
  • Options
    julkifli33julkifli33 Member Posts: 1,073
    if i not validate, still happened
    i think it because when we move to another line
    example from line 1 to line 2
    because if we only have 1 item in 1 document, there is no problem
    still haven't solve this issue
  • Options
    dansdans Member Posts: 148
    why not debug ?
    Microsoft Certified IT Professional for Microsoft Dynamics NAV

    Just a happy frood who knows where his towel is
  • Options
    julkifli33julkifli33 Member Posts: 1,073
    dans wrote:
    why not debug ?
    no error... but the result is wrong
    can we debug it?
  • Options
    dansdans Member Posts: 148
    just turn on the debugger (active and breakpoint)
    Microsoft Certified IT Professional for Microsoft Dynamics NAV

    Just a happy frood who knows where his towel is
  • Options
    julkifli33julkifli33 Member Posts: 1,073
    dans wrote:
    just turn on the debugger (active and breakpoint)
    still no clue
    i block my validation for item no in sales line
    but still the same result
    do you think on insert in sales line table?
  • Options
    SavatageSavatage Member Posts: 7,142
    What code do you have OnInsert of the Sales Line Table?

    Perhaps you can force it. how about changing the end part from
    SL.Imported := TRUE;
    SL.INSERT(TRUE);

    to
    SL.INSERT(TRUE);
    SL.Imported := TRUE;
    SL.MODIFY;
  • Options
    julkifli33julkifli33 Member Posts: 1,073
    Savatage wrote:
    What code do you have OnInsert of the Sales Line Table?

    Perhaps you can force it. how about changing the end part from
    SL.Imported := TRUE;
    SL.INSERT(TRUE);

    to
    SL.INSERT(TRUE);
    SL.Imported := TRUE;
    SL.MODIFY;
    i didnt add anything on my salesline table
    i tried your code , but the result still the same

    after insert, i also add this code
    still the same
    it's not working
    i starting to hopeless with this
    SL2.GET(SL."Document Type",SL."Document No.",SL."Line No.");
            SL2.Imported := TRUE;
            SL2."Description 2" := 'Imported';
            SL2.MODIFY(TRUE);
    
  • Options
    kapamaroukapamarou Member Posts: 1,152
    So strange... Could your field be a flowfield? :-k
Sign In or Register to comment.