Dynamically change import status of Dataport.

RoelofRoelof Member Posts: 377
Hi,

I have a question regarding dynamically changing the 'IMPORT' option on a Dataport. When I use this like:

DataportName.IMPORT(FALSE);
DataportName.RUN;

it is not being set as an export. How can I dynamically change that?

Roelof de Jong.
Roelof de Jonghttp://www.wye.com

Comments

  • kinekine Member Posts: 12,562
    I think it is working, only the reequest form is not updated...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • RoelofRoelof Member Posts: 377
    Well, the problem is, when I enter a filename, it is asking for an importfilename while I have set it as an export.
    I get an error when you enter a filename which is not existing because it needs to be an export file.
    Roelof de Jonghttp://www.wye.com
  • kinekine Member Posts: 12,562
    What about property "Import" in Dataport properties? ;-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • RoelofRoelof Member Posts: 377
    Does nog work.
    Roelof de Jonghttp://www.wye.com
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    I think you need to have a realy good look at all the properties/code in your dataport. It should work, realy. :?
  • pdjpdj Member Posts: 643
    I think you need to have a realy good look at all the properties/code in your dataport. It should work, realy. :?
    I should - yes.... However; it doesn't :-(
    I have had the exact same problem and have reproduced it very simple:
    OBJECT Dataport 50000 Test Dataport
    {
      OBJECT-PROPERTIES
      {
        Dato=01-12-05;
        Tid=20:56:44;
        Rettet=Ja;
        Versionsliste=;
      }
      PROPERTIES
      {
      }
      DATAITEMS
      {
      }
      REQUESTFORM
      {
        PROPERTIES
        {
          Width=9020;
          Height=3410;
          OnOpenForm=BEGIN
                       SetImport;
                     END;
    
        }
        CONTROLS
        {
          { 1   ;TextBox      ;3410 ;0    ;5610 ;440  ;AssistEdit=Ja;
                                                       SourceExpr=g_Filename }
          { 1000000001;Label  ;0    ;0    ;3300 ;440  ;ParentControl=1 }
          { 1000000002;OptionButton;3410;660;3740;440 ;SourceExpr=g_Direction;
                                                       OptionValue=Export;
                                                       OnValidate=BEGIN
                                                                    SetImport;
                                                                  END;
                                                                   }
          { 1000000003;Label  ;0    ;660  ;3300 ;440  ;ParentControl=1000000002 }
          { 1000000004;OptionButton;3410;1210;3740;440;SourceExpr=g_Direction;
                                                       OptionValue=Import;
                                                       OnValidate=BEGIN
                                                                    SetImport;
                                                                  END;
                                                                   }
          { 1000000006;CheckBox;3410;1980 ;440  ;440  ;ShowCaption=Nej;
                                                       CaptionML=DAN=CurrDataport.IMPORT;
                                                       SourceExpr=CurrDataport.IMPORT }
          { 1000000007;Label  ;0    ;1980 ;3300 ;440  ;ParentControl=1000000006 }
        }
      }
      CODE
      {
        VAR
          g_Filename@1000000001 : Text[250];
          g_Direction@1000000000 : 'Export,Import';
    
        PROCEDURE SetImport@1000000000();
        BEGIN
          CASE g_Direction OF
            g_Direction::Import: CurrDataport.IMPORT := TRUE;
            g_Direction::Export: CurrDataport.IMPORT := FALSE;
          END;
        END;
    
        BEGIN
        END.
      }
    }
    
    I guess you have to change to header part and Ja/Nej to Yes/No or what your stx file expect - other than that it should be straightforward to reproduce. Tested in 3.60 and 4.00-Update1 with same result. The only solution I know is to use Common Dialog, either directly or via codeunit 412.

    Edit: The above sample reproduce the problem directly in a dataport, but if you remove the code in OnOpenForm you will get the same result as the original post.
    Regards
    Peter
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    What about storing in a global variable and update the IMPORT thingy in the predataport trigger??

    EDIT: No that won;t help... that's to late.

    Well, fortunately there is codeunit 412
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    AAAARRGGH :twisted:

    I should not read mibuso this late, and with a beer!

    You forgot to update the CurrReport.FILENAME

    Just put this in your funtion....

    I realy should get a social life :mrgreen:

    I HATE winter...

    No Gardening
    No Motorbiking
    No Carpenting
    No Noting

    Just Internet 8)
  • pdjpdj Member Posts: 643
    I know I don't update the filename, but it doesn't change anything. Didn't you notice that there is no Dataitem, so it doesn't import or export much? 8)
    AAAARRGGH :twisted:
    I should not read mibuso this late, and with a beer!

    Well, you are not the only one in this timezone, but I got the flu and no beer :cry:
    Regards
    Peter
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    OBJECT Dataport 50000 Test Dataport
    {
      OBJECT-PROPERTIES
      {
        Datum=01-12-03;
        Tijd=22:19:19;
        Gewijzigd=Ja;
        Versie=;
      }
      PROPERTIES
      {
        OnPreDataport=BEGIN
                        CurrDataport.FILENAME := g_Filename;
                      END;
    
      }
      DATAITEMS
      {
        { PROPERTIES
          {
            DataItemTable=Table50000;
          }
          FIELDS
          {
            {      ;     ;test                 }
          }
           }
      }
      REQUESTFORM
      {
        PROPERTIES
        {
          Width=9020;
          Height=3410;
          OnOpenForm=BEGIN
                       SetImport;
                     END;
    
        }
        CONTROLS
        {
          { 1   ;TextBox      ;3410 ;0    ;5610 ;440  ;AssistEdit=Ja;
                                                       SourceExpr=g_Filename }
          { 1000000001;Label  ;0    ;0    ;3300 ;440  ;ParentControl=1 }
          { 1000000002;OptionButton;3410;660;3740;440 ;SourceExpr=g_Direction;
                                                       OptionValue=Export;
                                                       OnValidate=BEGIN
                                                                    SetImport;
                                                                  END;
                                                                   }
          { 1000000003;Label  ;0    ;660  ;3300 ;440  ;ParentControl=1000000002 }
          { 1000000004;OptionButton;3410;1210;3740;440;SourceExpr=g_Direction;
                                                       OptionValue=Import;
                                                       OnValidate=BEGIN
                                                                    SetImport;
                                                                  END;
                                                                   }
          { 1000000006;CheckBox;3410;1980 ;440  ;440  ;ShowCaption=Nee;
                                                       CaptionML=DAN=CurrDataport.IMPORT;
                                                       SourceExpr=CurrDataport.IMPORT }
          { 1000000007;Label  ;0    ;1980 ;3300 ;440  ;ParentControl=1000000006 }
        }
      }
      CODE
      {
        VAR
          g_Filename@1000000001 : Text[250];
          g_Direction@1000000000 : 'Export,Import';
    
        PROCEDURE SetImport@1000000000();
        BEGIN
          CASE g_Direction OF
            g_Direction::Import: CurrDataport.IMPORT := TRUE;
            g_Direction::Export: CurrDataport.IMPORT := FALSE;
          END;
        END;
    
        BEGIN
        END.
      }
    }
    

    Well! This works \:D/

    And I'm drinking my 2nd beer now :mrgreen:

    Guess I should start drinking during working hours :wink:

    Good luck surviving the flu!
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    PS. I've put in a simpe test table containing one text field.
  • RobertMoRobertMo Member Posts: 484
    Hi all!

    I think there are 2 problems here, but only one was answered.

    1) It is pretty well explained how to simulate the Filename and Direction controls in order to have even more controls on the request form.

    2) But this solution has a problem, which was expressed also by Roleof:
    ...the problem is, when I enter a filename, it is asking for an import filename while I have set it as an export. I get an error when you enter a filename which is not existing because it needs to be an export file.

    The problem is that the "control simulation" is not perfect. Although the code OnValidate changes the setting of CurrDataport.IMPORT to Export, the Assist Edit on the filename behaves always the same way - that is opening a dialog Dataport Import File Name. Of course the very same dialog insists that the file should exist before, and therefore issuing an error, if you actually want to export to a new file.

    The workaround is to additionally set the default Dataport property IMPORT to NO!
    This way the dialog that opens for file selection will always be Dataport Export File Name. These is perfect when actually exporting, but when importing, the dialog will accept also un-existing filenames (which is not ok) but will at least close. Of course when hitting the OK button on the Dataport it will again check the file existence and issue an error if the filename actually doesn't exist.

    Simple as that \:D/ So no Common Dialog programming or CU412.

    BTW, it's been a while since I was around here, so greets to all.
               ®obi           
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  • awarnawarn Member Posts: 261
    RobertMo,

    GREAT tip - this does exactly what I want!

    I especially like the lack of any dialog programming!

    -a
  • Yaroslav_GaponovYaroslav_Gaponov Member Posts: 158
    Roelof wrote:
    Hi,

    I have a question regarding dynamically changing the 'IMPORT' option on a Dataport. When I use this like:

    DataportName.IMPORT(FALSE);
    DataportName.RUN;

    it is not being set as an export. How can I dynamically change that?

    Roelof de Jong.

    Hi All,

    It's stupidly ](*,) but for dynamically changing Import option necessary default <Yes> Import property of the dataport changed just to Yes or No and code will be work \:D/
  • colingbradleycolingbradley Member Posts: 162
    I am not having any success despite reading the threads here.

    I need to export Table 18 from Navision 3.7.

    Dataport - OnPreDataport()
    CurrDataport.IMPORT(FALSE);
    SRSetup.GET;
    gvDateTime := CREATEDATETIME(TODAY, TIME);
    gvFileName := SRSetup."Path for Data Export" + 'COMPANYNAME' + '-' + FORMAT(gvDateTime);
    CurrDataport.FILENAME(gvFileName);

    Properties:
    Import = No
    UseReqForm = No

    I am getting an error:
    "The operating system cannot find the drive and directory specified for the file Q:\BusinessServices\PDF_Invoices\CGB\Brazil\COMPANYNAME-03/06/13 17:02 .Please check that the drive, directory and file names are correct."

    Why is it looking for a file to import?

    Is there any way to force the file name for the Export in the way I need it?
    Experience is what you get when you hoped to get money
  • SavatageSavatage Member Posts: 7,142
    looks good :-k
    2 things.

    1) the file name I would suggest adding a +'.txt' at the end.
    2) did you try to simply the path to see if that works?

    so instead of Q:\BusinessServices\PDF_Invoices\CGB\Brazil\
    try c:\ (just to see if that works)
    then q:\ then keep adding a directory to see where it fails.
  • vaprogvaprog Member Posts: 1,141
    Your generated filename is invalid. Do not use slashes nor colons.
    In filenames, sometimes, Windows treats forward slashes like backslashes as folder separators. So, the error message probably is caused while trying to create the export file.
  • colingbradleycolingbradley Member Posts: 162
    \:D/
    Result!
    Thanks to both of you for the help and good advice.

    Abc Co Ltd040613 0952.txt

    Final code:
    Dataport - OnPreDataport()
    CurrDataport.IMPORT(FALSE);
    SRSetup.GET;
    gvDateTime := CREATEDATETIME(TODAY, TIME);
    gvDateTimeText := FORMAT(gvDateTime);
    gvDateTimeText := DELCHR(gvDateTimeText,'=',':'); /// remove colons
    gvDateTimeText := DELCHR(gvDateTimeText,'=','/'); /// remove forward slashes
    gvFileName := SRSetup."Path for Data Export" + COMPANYNAME + gvDateTimeText + '.txt';
    CurrDataport.FILENAME(gvFileName);

    The path was not the problem but I did try first with c:\ then went for it.
    Experience is what you get when you hoped to get money
Sign In or Register to comment.