Writing line before and after the dataport exports lines

Cem_KaraerCem_Karaer Member Posts: 281
edited 2010-11-25 in NAV Tips & Tricks
Hello all,

Say that you want to export purchase lines to a text file but want to write

purchase

before all of the lines and

end_purchase

after all of the lines. Then you can do something like the following code:
OBJECT Dataport 50000 Export Purch. to PORTAL
{
  OBJECT-PROPERTIES
  {
    Date=25.11.10;
    Time=16:52:20;
    Modified=Yes;
    Version List=Parge-PORTAL;
  }
  PROPERTIES
  {
    CaptionML=[ENU=Export Purch. to PORTAL;
               TRK=Satnalma PORTAL DŸar Aktar];
    Import=No;
    FileName=C:\text.txt;
    FieldStartDelimiter=<None>;
    FieldEndDelimiter=<None>;
    FieldSeparator=[;];
    OnInitDataport=BEGIN
                     PurchSetup.GET;
                     PurchSetup.TESTFIELD("Purch. Order Outgoing Path");
                   END;

    OnPreDataport=BEGIN
                    VendorFilter := "Purchase Line".GETFILTER("Buy-from Vendor No.");
                    CurrDataport.FILENAME := PurchSetup."Purch. Order Outgoing Path" +
                                               VendorFilter + '-' + FORMAT(CURRENTDATETIME,0,'<Year4><Month,2><Day,2><Hour,2><Minute,2>') + '.csv';
                  END;

  }
  DATAITEMS
  {
    { PROPERTIES
      {
        DataItemTable=Table2000000026;
        DataItemVarName=Up;
        DataItemTableView=SORTING(Number)
                          WHERE(Number=CONST(1));
      }
      FIELDS
      {
        {      ;     ;'receipt'            }
      }
       }
    { PROPERTIES
      {
        DataItemTable=Table39;
        DataItemTableView=WHERE(Document Type=CONST(Order),
                                Type=CONST(Item),
                                Outstanding Quantity=FILTER(>0));
        ReqFilterFields=Buy-from Vendor No.;
        OnPreDataItem=BEGIN
                        CurrFile.OPEN(CurrFile.NAME);
                        CurrFile.SEEK(CurrFile.LEN - 2);
                      END;

        OnBeforeExportRecord=BEGIN
                               PurchHeader.GET("Document Type","Document No.");
                               Item.INIT;
                               IF Item.GET("No.") THEN;
                               txtDate := FORMAT(PurchHeader."Posting Date",0,'<Day,2>/<Month,2>/<Year4>');
                             END;

      }
      FIELDS
      {
        {      ;     ;"Buy-from Vendor No." }
        {      ;     ;"No."                }
        {      ;     ;Quantity             }
        {      ;     ;"Unit of Measure"    }
        {      ;     ;txtDate              }
        {      ;     ;''                   }
        {      ;     ;txtDate              }
        {      ;     ;CURRENTDATETIME      }
        {      ;     ;"Line No."           }
        {      ;     ;"Document No."       }
      }
       }
    { PROPERTIES
      {
        DataItemTable=Table2000000026;
        DataItemVarName=Down;
        DataItemTableView=SORTING(Number)
                          WHERE(Number=CONST(1));
        OnPreDataItem=BEGIN
                        CurrFile.OPEN(CurrFile.NAME);
                        CurrFile.SEEK(CurrFile.LEN - 2);
                      END;

      }
      FIELDS
      {
        {      ;     ;'end_receipt'        }
      }
       }
  }
  REQUESTFORM
  {
    PROPERTIES
    {
      Width=9020;
      Height=3410;
    }
    CONTROLS
    {
    }
  }
  CODE
  {
    VAR
      PurchHeader@1000000000 : Record 38;
      Item@1000000001 : Record 27;
      PurchSetup@1000000002 : Record 312;
      VendorFilter@1000000003 : Code[20];
      txtDate@1000000004 : Text[30];

    BEGIN
    END.
  }
}

There are some codes which are customer specific. The point is to use
CurrFile.OPEN(CurrFile.NAME);
CurrFile.SEEK(CurrFile.LEN - 2);

in the OnPreDataItem of the integer dataitems.
Cem Karaer @ Pargesoft
Dynamics NAV Developer since 2005
Sign In or Register to comment.