dataport based on temporay table

ASTAST Member Posts: 108
Hi,
I have dataport based on temporary table - it works, but I need something more. I need to export only choosen set of fields from Dataport fields. Elements (fields) on set depends on one value in this temporary table, e.g.

Dataport fields
f1
f2
.
.
.
fn


if f1 = value 1 then
"export fields: f2,f3,f5"
if f1 = value 2 then
"export fields: f6,f8,f10"
......

Comments

  • ara3nara3n Member Posts: 9,256
    And your question is?
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ASTAST Member Posts: 108
    My question is How to do this. Can I select fileds to export with C/AL?
  • ara3nara3n Member Posts: 9,256
    Can you do it with C/AL sure.

    Do you want this selection at run time?

    Post your dataport. Need more information.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • NaviDevNaviDev Member Posts: 365
    Just a suggestion.

    Why not pass it to a recordref and use the fieldref and do your exporting manipulation.
    Navision noob....
  • ASTAST Member Posts: 108
    Do you want this selection at run time?
    Yes, I need it at run time - I need selection for each record depends on one value ("Transfer Type") in this record.

    That,s my dataport
    OBJECT Dataport 50000 Export Transfer File
    {
      OBJECT-PROPERTIES
      {
        Date=08-11-07;
        Time=10:03:42;
        Modified=Yes;
        Version List=;
      }
      PROPERTIES
      {
        Import=No;
        FieldStartDelimiter=<None>;
        FieldEndDelimiter=<None>;
        FieldSeparator=|;
        UseReqForm=Yes;
      }
      DATAITEMS
      {
        { PROPERTIES
          {
            DataItemTable=Table2000000026;
            OnPreDataItem=BEGIN
                            TransferFileBuffer.RESET;
                            SETRANGE(Number,1,TransferFileBuffer.COUNT);
                          END;
    
            OnAfterExportRecord=BEGIN
                                  IF Number = 1 THEN BEGIN
                                    TransferFileBuffer.FIND('-');
                                  END
                                  ELSE
                                    TransferFileBuffer.NEXT;
                                END;
    
          }
          FIELDS
          {
            { 1    ;10   ;TransferFileBuffer."Transfer Type" }
            { 12   ;200  ;TransferFileBuffer.Title }
            { 213  ;7    ;TransferFileBuffer.CIF }
            { 221  ;30   ;TransferFileBuffer."Bank account" }
            .......................................................................
          }
           }
      }
      REQUESTFORM
      {
        PROPERTIES
        {
          Width=9020;
          Height=3410;
        }
        CONTROLS
        {
        }
      }
      CODE
      {
        VAR
          TransferFileBuffer@1170000 : TEMPORARY Record 60002;
          i@1170001 : Integer;
          text@1170002 : Text[30];
    
        PROCEDURE FillTempTable@1170001(VAR Buffer@1170000 : TEMPORARY Record 60002);
        BEGIN
          Buffer.RESET;
          IF Buffer.FIND('-') THEN
            REPEAT
              TransferFileBuffer := Buffer;
              TransferFileBuffer.INSERT(FALSE);
            UNTIL Buffer.NEXT = 0;
        END;
    
        BEGIN
        END.
      }
    }
    
  • ASTAST Member Posts: 108
    Why not pass it to a recordref and use the fieldref and do your exporting manipulation.
    I'm not sure what do you mean...
    When I pass it to a recordref I also have to select a set to export.
    Could you please explain your point?
  • EugeneEugene Member Posts: 309
    you will have to do it manually (write to a file with yourself) by using CurrFile variable's functions
  • Kerem_KiziltuncKerem_Kiziltunc Member, Microsoft Employee Posts: 10
    You can also use a set of global temporary variables to store the fields you want to export. This would allow you to continue using the Request Form and the file dialog functionality of the Dataport.

    You can define three variables called column1, column2 and column3, of type text. These would be the SourceExpressions in your Field Designer.

    Then you can add the following code to your Dataport:
    Integer - OnBeforeExportRecord()
    IF TransferFileBuffer."Transfer Type" ='Odd' THEN
    BEGIN
      column1 := FORMAT(TransferFileBuffer.F2);
      column2 := FORMAT(TransferFileBuffer.F3);
      column3 := FORMAT(TransferFileBuffer.F5);
    END ELSE
    BEGIN
      column1 := FORMAT(TransferFileBuffer.F6);
      column2 := FORMAT(TransferFileBuffer.F8);
      column3 := FORMAT(TransferFileBuffer.F10);
    END;
    

    Assuming that we have this table:
    OBJECT Table 60002 Transfer
    {
      OBJECT-PROPERTIES
      {
        Date=08-11-07;
        Time=16:51:44;
        Modified=Yes;
        Version List=;
      }
      PROPERTIES
      {
      }
      FIELDS
      {
        { 1   ;   ;F1                  ;Code10         }
        { 2   ;   ;Transfer Type       ;Text30         }
        { 3   ;   ;F2                  ;Text30         }
        { 4   ;   ;F3                  ;Decimal        }
        { 5   ;   ;F10                 ;Integer        }
        { 6   ;   ;F5                  ;Decimal        }
        { 7   ;   ;F6                  ;Integer        }
        { 8   ;   ;F7                  ;Text30         }
        { 9   ;   ;F8                  ;Code10         }
      }
      KEYS
      {
        {    ;F1                                      ;Clustered=Yes }
      }
      FIELDGROUPS
      {
      }
      CODE
      {
    
        BEGIN
        END.
      }
    }
    
    

    Our Dataport would look like this:
    OBJECT Dataport 50000 Export Transfer File
    {
      OBJECT-PROPERTIES
      {
        Date=08-11-07;
        Time=16:55:56;
        Modified=Yes;
        Version List=;
      }
      PROPERTIES
      {
        Import=No;
        FieldStartDelimiter=<None>;
        FieldEndDelimiter=<None>;
        FieldSeparator=|;
        UseReqForm=Yes;
        OnInitDataport=BEGIN
                         FillTempTable(TransferFileBuffer);
                       END;
    
      }
      DATAITEMS
      {
        { PROPERTIES
          {
            DataItemTable=Table2000000026;
            OnPreDataItem=BEGIN
                            TransferFileBuffer.RESET;
                            SETRANGE(Number,1,TransferFileBuffer.COUNT);
                          END;
    
            OnBeforeExportRecord=BEGIN
                                   IF TransferFileBuffer."Transfer Type" ='Odd' THEN
                                   BEGIN
                                     column1 := FORMAT(TransferFileBuffer.F2);
                                     column2 := FORMAT(TransferFileBuffer.F3);
                                     column3 := FORMAT(TransferFileBuffer.F5);
                                   END ELSE
                                   BEGIN
                                     column1 := FORMAT(TransferFileBuffer.F6);
                                     column2 := FORMAT(TransferFileBuffer.F8);
                                     column3 := FORMAT(TransferFileBuffer.F10);
                                   END;
                                 END;
    
            OnAfterExportRecord=BEGIN
                                  IF Number = 1 THEN BEGIN
                                    TransferFileBuffer.FIND('-');
                                  END
                                  ELSE
                                    TransferFileBuffer.NEXT;
                                END;
    
          }
          FIELDS
          {
            { 1    ;10   ;column1              }
            { 12   ;200  ;column2              }
            { 213  ;7    ;column3              }
          }
           }
      }
      REQUESTFORM
      {
        PROPERTIES
        {
          Width=9020;
          Height=3410;
        }
        CONTROLS
        {
        }
      }
      CODE
      {
        VAR
          TransferFileBuffer@1170000 : TEMPORARY Record 60002;
          i@1170001 : Integer;
          text@1170002 : Text[30];
          column1@1102601000 : Text[30];
          column2@1102601001 : Text[30];
          column3@1102601002 : Text[30];
    
        PROCEDURE FillTempTable@1170001(VAR Buffer@1170000 : TEMPORARY Record 60002);
        BEGIN
          Buffer.RESET;
          IF Buffer.FIND('-') THEN
            REPEAT
              TransferFileBuffer := Buffer;
              TransferFileBuffer.INSERT(FALSE);
            UNTIL Buffer.NEXT = 0;
        END;
    
        BEGIN
        END.
      }
    }
    
    
    “This posting is provided "AS IS" with no warranties, and confers no rights.”
  • ASTAST Member Posts: 108
    You can also use a set of global temporary variables to store the fields you want to export.
    Thanks a lot, it would be a good idea, but my sets have different number of elements, so it can't work :(
  • ASTAST Member Posts: 108
    I could create several dataports - based on the same temporary table but with different dataport fileds. Then I could do something like that
    if val1 
      run Dataport1
    if val2 
      run Dataport2
    ......
    

    but how to write several dataports to the same file not override it? :-k
  • ASTAST Member Posts: 108
    Or maybe I could write one dataport to regular file and the rest of dataports to temporary file and then copy each temporary file to the end of regular file?
    It is good idea?
    Or maybe I just should write to file manually? I have from 19 to 32 fields for each record and I need sparator '|' between fields. #-o
  • Kerem_KiziltuncKerem_Kiziltunc Member, Microsoft Employee Posts: 10
    Would defining a single line global variable of type Text255 help? Your code would look like this:
    Integer - OnBeforeExportRecord()
    IF TransferFileBuffer."Transfer Type" ='Odd' THEN
    BEGIN
      line:= FORMAT(TransferFileBuffer.F2) + '|' + FORMAT(TransferFileBuffer.F3) + '|' + FORMAT(TransferFileBuffer.F5)
    END ELSE
    BEGIN
      line:= FORMAT(TransferFileBuffer.F6) + '|' + FORMAT(TransferFileBuffer.F8);
    END;
    

    where line is the SourceExpression for your only entry in Field Designer.

    You may need to do additional padding using the PADSTR(String, Length [, FillCharacter]) function, if you need that.
    “This posting is provided "AS IS" with no warranties, and confers no rights.”
  • ASTAST Member Posts: 108
    Would defining a single line global variable of type Text255 help?
    That's what I try to avoid - becouse I have a lot of fields to export.
  • Kerem_KiziltuncKerem_Kiziltunc Member, Microsoft Employee Posts: 10
    I have one other proposal. This won't work if you have to sort your output based on a field other than TransferType, but for the sake of completion I will mention it.

    You can have two DataItems on the Xml Port. They would have different DataItemTableView properties, filtering on the TransferType field (doing the same thing with the if TransferType = ... statement we used before). Since each DataItem can have a different set of DataPort Fields list, the only thing you need to do is to set the DataItemSeparator property to <NewLine>, so that output will not have a blank line in between.

    Assuming that TransferType can be 'Odd' or 'Even' only, I defined two DataItems with corresponding filters. (I also removed the temporary table from code.)

    The problem with this is the two RequestForm tabs you get in addition to Options tab. But if you are able to suppress the RequestForm, it should not be a problem.

    Code looks like this, then:
    OBJECT Dataport 50000 Export Transfer File
    {
      OBJECT-PROPERTIES
      {
        Date=11-11-07;
        Time=00:41:50;
        Modified=Yes;
        Version List=;
      }
      PROPERTIES
      {
        Import=No;
        FieldStartDelimiter=<None>;
        FieldEndDelimiter=<None>;
        FieldSeparator=|;
        DataItemSeparator=<NewLine>;
        UseReqForm=Yes;
        OnInitDataport=VAR
                         transfer@1102601000 : Record 60002;
                       BEGIN
                       END;
    
      }
      DATAITEMS
      {
        { PROPERTIES
          {
            DataItemTable=Table60002;
            DataItemVarName=OddTransfers;
            DataItemTableView=WHERE(Transfer Type=CONST(Odd));
          }
          FIELDS
          {
            {      ;     ;F2                   }
            {      ;     ;F3                   }
            {      ;     ;F5                   }
          }
           }
        { PROPERTIES
          {
            DataItemTable=Table60002;
            DataItemVarName=EvenTransfers;
            DataItemTableView=WHERE(Transfer Type=CONST(Even));
          }
          FIELDS
          {
            {      ;     ;F6                   }
            {      ;     ;F8                   }
          }
           }
      }
      REQUESTFORM
      {
        PROPERTIES
        {
          Width=9020;
          Height=3410;
        }
        CONTROLS
        {
        }
      }
      CODE
      {
    
        BEGIN
        END.
      }
    }
    
    
    “This posting is provided "AS IS" with no warranties, and confers no rights.”
Sign In or Register to comment.