Dataport SKIP

tazzy30tazzy30 Member Posts: 52
Hello,

I have created a dataport which imports Purchase Invoices, the dataport works fine if the CSV file has only header details, but as soon as lines are added, it doesn't work.

It appears the CurrDataport.SKIP in the header dataitem is not triggered.
IF PurchaserCode <>'' THEN BEGIN
  PurchHead."Buy-from Vendor No." := PurchaserCode;
 IF NOT Vend.GET(PurchHead."Buy-from Vendor No.") THEN BEGIN
    Vend.INIT;
    Vend."No." := PurchHead."Buy-from Vendor No.";
    Vend.INSERT;
  END;

PurchHead.VALIDATE("Buy-from Vendor No.",PurchaserCode);
PurchHead.VALIDATE("Shortcut Dimension 1 Code",Dept);
PurchHead.VALIDATE("Shortcut Dimension 2 Code",SBC);
PurchHead."Your Reference" := Notes;
PurchHead.MODIFY;
CurrDataport.SKIP;

END ELSE
  ERROR('Employee has not been specified.');

Does anyone have any idea what this could be?
Thank You

Comments

  • BeliasBelias Member Posts: 2,998
    First, i indented your code properly, check if it's what you want
    IF PurchaserCode <>'' THEN BEGIN
      PurchHead."Buy-from Vendor No." := PurchaserCode;
      
      IF NOT Vend.GET(PurchHead."Buy-from Vendor No.") THEN BEGIN
        Vend.INIT;
        Vend."No." := PurchHead."Buy-from Vendor No.";
        Vend.INSERT;
      END;
    
      PurchHead.VALIDATE("Buy-from Vendor No.",PurchaserCode);
      PurchHead.VALIDATE("Shortcut Dimension 1 Code",Dept);
      PurchHead.VALIDATE("Shortcut Dimension 2 Code",SBC);
      PurchHead."Your Reference" := Notes;
      PurchHead.MODIFY;
      CurrDataport.SKIP;
    
    END ELSE
      ERROR('Employee has not been specified.');
    

    then, why do you want to skip a line after you've done modifications?what do you think you'll skip?
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • tazzy30tazzy30 Member Posts: 52
    Thank You for your reply, If i dont put a Skip then it reads the next line in the CSV file as a header as supposed to a line (second dataitem)
  • BeliasBelias Member Posts: 2,998
    currdataport.skip does not skip a line in the file, but a record in NAV (useless in your situation).
    maybe you can post your dataport and/or a sample of csv file?
    anyway, i think that for complex importations, it's better to use a report and FILE functions
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • tazzy30tazzy30 Member Posts: 52
    Thank you for your reply i would attach the items on here but i cant see the option to do so
  • BeliasBelias Member Posts: 2,998
    tazzy30 wrote:
    Thank you for your reply i would attach the items on here but i cant see the option to do so
    export in text and copy/paste in a message ;)
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • tazzy30tazzy30 Member Posts: 52
    Thank You, this is CSV

    40000,ADM,MERCEDES,Testing,Test Proj (Purchase Header)
    (Empty Line)
    5410,Mileage,115,0.4,GBP,,1,,5,46 (Purchase Lines)

    This is the dataport
    OBJECT Dataport 50001 Purchase Invoice Import
    {
      OBJECT-PROPERTIES
      {
        Date=19/03/09;
        Time=12:04:47;
        Modified=Yes;
        Version List=;
      }
      PROPERTIES
      {
      }
      DATAITEMS
      {
        { PROPERTIES
          {
            DataItemTable=Table2000000026;
            DataItemVarName=PurchaseHeader;
            AutoSave=No;
            DataItemTableView=SORTING(Number);
            OnPreDataItem=BEGIN
                            PurchHead."Document Type" := PurchHead."Document Type"::Invoice;
                          END;
    
            OnAfterImportRecord=BEGIN
                                  IF PurchaserCode <>'' THEN BEGIN
                                    PurchHead."Buy-from Vendor No." := PurchaserCode;
                                   IF NOT Vend.GET(PurchHead."Buy-from Vendor No.") THEN BEGIN
                                      Vend.INIT;
                                      Vend."No." := PurchHead."Buy-from Vendor No.";
                                      Vend.INSERT;
                                    END;
    
                                    PurchHead.VALIDATE("Buy-from Vendor No.",PurchaserCode);
                                    PurchHead.VALIDATE("Shortcut Dimension 1 Code",Dept);
                                    PurchHead.VALIDATE("Shortcut Dimension 2 Code",SBC);
    
                                  IF ProjectCode <>'' THEN
                                    DocDim.INIT;
                                    DocDim."Table ID" := 38;
                                    DocDim."Document Type" := DocDim."Document Type"::Invoice;
                                    DocDim."Document No." := PurchHead."No.";
                                    DocDim."Dimension Code" := 'PROJECT';
                                    DocDim."Dimension Value Code" := ProjectCode;
                                    DocDim.VALIDATE("Dimension Value Code", ProjectCode);
    
                                    PurchHead."Your Reference" := Notes;
                                    PurchHead.MODIFY;
                                    CurrDataport.SKIP;
    
                                  {END ELSE
                                    ERROR('Employee has not been specified.');}
                                  END;
                                END;
    
          }
          FIELDS
          {
            {      ;     ;PurchaserCode        }
            {      ;     ;Dept                 }
            {      ;     ;SBC                  }
            {      ;     ;Notes                }
            {      ;     ;Project              }
          }
           }
        { PROPERTIES
          {
            DataItemTable=Table2000000026;
            DataItemVarName=PurchaseLine;
            AutoSave=No;
            DataItemTableView=SORTING(Number);
            OnPreDataItem=BEGIN
                            PurchLine."Document Type" := PurchLine."Document Type"::Invoice;
                            LineNo := 10000;
                          END;
    
            OnBeforeImportRecord=BEGIN
                                   CLEAR(PurchLine)
                                 END;
    
            OnAfterImportRecord=BEGIN
                                  IF (AccountCode = '') AND (Desc = '') THEN
                                    CurrDataport.SKIP;
                                  GLAcc := COPYSTR(AccountCode,1,4);
                                  PurchLine."Document No." := PurchHead."No.";
                                  PurchLine."Line No." := LineNo;
                                  LineNo += 10000;
                                  PurchLine."Buy-from Vendor No." := PurchHead."Buy-from Vendor No.";
                                  IF TotalAmount = 0 THEN BEGIN
                                    IF NOT INSERT THEN MODIFY;
                                    CurrDataport.SKIP;
                                  END;
    
                                  TempLine := PurchLine;
                                  PurchLine.VALIDATE(Type,PurchLine.Type::"G/L Account");
                                  PurchLine.VALIDATE("No.",GLAcc);
                                  PurchLine.Description := Desc;
                                  PurchLine.VALIDATE("Shortcut Dimension 1 Code",TempLine."Shortcut Dimension 1 Code");
                                  PurchLine.VALIDATE("Shortcut Dimension 2 Code",TempLine."Shortcut Dimension 2 Code");
                                  PurchLine.VALIDATE("VAT Prod. Posting Group", VATProdPostGrp);
    
                                  IF Miles <> 0 THEN BEGIN
                                    PurchLine.VALIDATE(Quantity,Miles);
                                    PurchLine.VALIDATE("Direct Unit Cost",UnitCost);
                                  END ELSE BEGIN
                                    PurchLine.VALIDATE(Quantity,1);
                                    PurchLine.VALIDATE("Direct Unit Cost",TotalAmount);
                                  END;
                                  IF NOT INSERT THEN MODIFY;
                                END;
    
          }
          FIELDS
          {
            {      ;     ;AccountCode          }
            {      ;     ;Desc                 }
            {      ;     ;Miles                }
            {      ;     ;UnitCost             }
            {      ;     ;PurchLine."Currency Code" }
            {      ;     ;LocalCurrAmt         }
            {      ;     ;ExchangeRate         }
            {      ;     ;PurchLine."Direct Unit Cost" }
            {      ;     ;VATProdPostGrp       }
            {      ;     ;TotalAmount          }
          }
           }
      }
      REQUESTFORM
      {
        PROPERTIES
        {
          Width=9020;
          Height=3410;
        }
        CONTROLS
        {
        }
      }
      CODE
      {
        VAR
          PurchaserCode@1040000 : Code[10];
          Dept@1040001 : Code[10];
          SBC@1040002 : Code[10];
          Notes@1040003 : Text[30];
          Project@1040004 : Code[10];
          PurchHead@1040005 : Record 38;
          PurchLine@1040006 : Record 39;
          Vend@1040007 : Record 23;
          ProjectCode@1040008 : Code[20];
          DocDim@1040009 : Record 357;
          LineNo@1040010 : Integer;
          VATProdPostGrp@1040011 : Code[10];
          TotalAmount@1040012 : Decimal;
          Desc@1040013 : Text[250];
          ExpItemNo@1040016 : Integer;
          Date@1040017 : Date;
          LocalCurrAmt@1040018 : Decimal;
          ExchangeRate@1040019 : Decimal;
          AccountCode@1040014 : Text[50];
          GLAcc@1040015 : Code[20];
          UnitCost@1040020 : Decimal;
          Miles@1040021 : Decimal;
          TempLine@1040022 : Record 39;
    
        PROCEDURE SetDocNo@1040000(BlankOrder@1040000 : Record 38);
        BEGIN
          PurchHead := BlankOrder
        END;
    
        BEGIN
        END.
      }
    }
    
    
  • BeliasBelias Member Posts: 2,998
    the problem is that you don't have a csv suitable for dataports, because you have
    header
    -
    line
    line
    line
    --
    header
    -
    line
    --
    header
    -
    line

    in this way it's difficult to figure out what dataitem you must fill in. for this reason, i suggest you to use a report or codeunit in order to manage the file as you want. (read the first line of the file, detect if it is an header or a line, insert the record in the appropriate table, go to the next line)

    If you have the possibility to change the csv to import, you should create something like:
    header
    header
    header
    header
    ...
    lastheader
    [carriage return x 2]
    line
    line
    line
    ...
    last line

    with this layout of the file, you can set the dataitemseparator property, then insert all the headers, and then all the lines
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • tazzy30tazzy30 Member Posts: 52
    Thank You for your reply, i should have stated that the csv file will only ever hold one Header and multiple lines, so would this still be the case?
  • BeliasBelias Member Posts: 2,998
    ok, then you have a csv file for each invoice...perferct, you just create a dataport with:
    -purchase header (put your business logic for header in this dataitem)
    -purchase lines (put your business logic for lines here)

    set dataitemseparator properly (i think that the standard "<<NewLine><NewLine>>" fits for you) leave to nav the rest...
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • BeliasBelias Member Posts: 2,998
    just imported your dataport...why did you use 2 integer dataitems instead of purchase header & line?
    if you want to insert/modify data manually by code, just set "auto" insert, modify, rename properties of the dataport to NO and then manage your code.
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • tazzy30tazzy30 Member Posts: 52
    I have also done this however had no luck, it just doesn't want to work :(
  • BeliasBelias Member Posts: 2,998
    i've see some strange logic in your dataport, but at the moment i've no time to write you...sorry, i'll help you as soon as possible...
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • tazzy30tazzy30 Member Posts: 52
    Ok thank you for taking the time out to look
  • tazzy30tazzy30 Member Posts: 52
    I'm still having the same problem does anyone have any idea's what this could be?
  • SavatageSavatage Member Posts: 7,142
    Start Again if your data always & only has

    header data
    (space)
    line data
    line data
    line data

    then your dataport will have both dataitems
    Purchase Header
    Purchase Line (not linked in anyway!)

    Fileformat - Variable
    Record Seperator <<NewLine>>
    DataItemSeperator <<Newline><NewLine>>

    I would create variables for the data you are importing.
    Put the var's for the header in the purchase header Dataport fields.
    put the var's for the lines in the purchase line dataport fields.

    Onafterimportrecord for purchase header add your code to match your var's to their proper nav field validate where necessary. (going to need at least "Document type" & "No.")
    Onafterimportrecord for purchase lines add your code to match your var's to their proper nav field validate where necessary. (going to need at least "Document Type", "Document no." & "Line no."
  • tazzy30tazzy30 Member Posts: 52
    Thank You for your reply Savatage, i have tried this but still no luck, I have inserted a MESSAGE and it seems to be reading everything correctly however the error at the end of the code still appears. :(
    IF "Buy-from Vendor No." <> '' THEN BEGIN
      IF NOT Vend.GET("Buy-from Vendor No.") THEN BEGIN
        Vend.INIT;
        Vend."No." := "Buy-from Vendor No.";
        Vend.INSERT;
      END;
    
      PurchaseHeader.VALIDATE("Buy-from Vendor No.","Buy-from Vendor No.");
      PurchaseHeader.VALIDATE("Shortcut Dimension 1 Code",Dept);
      PurchaseHeader.VALIDATE("Shortcut Dimension 2 Code",SBC);
    
      IF ProjectCode <>'' THEN BEGIN
        DocDim.INIT;
        DocDim."Table ID" := 38;
        DocDim."Document Type" := DocDim."Document Type"::Invoice;
        DocDim."Document No." := "No.";
        DocDim."Dimension Code" := 'PROJECT';
        DocDim."Dimension Value Code" := ProjectCode;
        DocDim.INSERT;
      END;
      DocDim.VALIDATE("Dimension Value Code", ProjectCode);
      PurchaseHeader."Your Reference" := Notes;
      
      PurchaseHeader.MODIFY;
      CurrDataport.SKIP;
    END ELSE
      ERROR('Employee has not been specified.');
    
    
  • SavatageSavatage Member Posts: 7,142
    1st...What error?
    2nd..Where are you defining a Purchase header? w/code?
    3rd..try just importing a purchase order first before adding all the bells n whistles like skipping & inserting vendor's n stuff.

    that can all come later.

    Here's a post that I put the simplest of simple dataports.
    It's for Sales Order - but easily changed to purchase orders.
    You can use it as a guide to get your dataport at least importing. once you get that working then add Inserting new vendors & skipping etc.
    viewtopic.php?t=16024
  • bgadhvi1bgadhvi1 Member Posts: 7
    Hi Tazzy :wink:

    I just had the exact issue with a similar dataport :wink:

    You need to use CurrDataport.BREAK not CurrDataport.SKIP to go onto the next dataitem, Skip will only go onto the next record, Break will skip the current dataitem onto the next.

    Hope that helps 'Tazzy'!! :D
  • SavatageSavatage Member Posts: 7,142
    bgadhvi1 wrote:
    Hope that helps 'Tazzy'!! :D
    Since the post was from 2009, I hoped he got his dataport working by now :wink:
Sign In or Register to comment.