Dataport Request Form

rtrammelrtrammel Member Posts: 5
Hello All,
We are using NAV 4.0 SP2 with SQL Server 2005. We are an enduser, and I have very little training with Navision. I am currently attempting to learn to program dataports. I can call a dataport from a codeunit to export data, however the request form opens. I tried to use the statement
USEREQUESTFORM(FALSE)
in the OnInitDataport trigger and get a compile error error stating
'You have specified an unknown variable.'
USEREQUESTFORM
'Define the variable inder 'Global C/AL symbols'.
I also tried calling it from a code unit in the OnRun trigger:

CLEAR(dp50117);
dp50117.SetVariables('002','A0422', First, Last);
dp50117.USEREQUESTFORM := FALSE;
dp50117.RUN;

Where dp50117 is the name of the variable name of the dataport .
I get same error message. With all this said could someone please explain the correct way to tell the dataport at run time not to use the request form. What I am trying to achieve is a dataport that can be run by a user and the request form will open, or be called from a code unit and the request form not open.

Thanks in advance for any advice.
Navision - ver. NA 4.00 (4.0 SP2)

Comments

  • Cem_KaraerCem_Karaer Member Posts: 281
    It is the reason why the request form shown that user will provide the dataport necessary information needed, for example filters to the data items, sorting of data items, the direction of data flow and path & name of the file to be imported or exported. If you provide all those data beforehand, there will be no need to show the request form. Set the sorting of data items, set the Import and FileName properties of the dataport then there will be no need to show the request form.
    Cem Karaer @ Pargesoft
    Dynamics NAV Developer since 2005
  • rtrammelrtrammel Member Posts: 5
    I understand the use of the dataport request form. What I asked was, how to make it not appear when the dataport is called from a codeunit. When I call a report from a code unit, I can set the USEREQUESTFORM property to FALSE and the Request form will not be used. I am unable to do this with the dataport, and asked for direction in achieving that.

    Thanks in advance.
    Navision - ver. NA 4.00 (4.0 SP2)
  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    If you assign a value (Yes or No) to the Import-property of your dataport, you don't get a requestform when the dataport is run. But then you'll also have to provide the filename through: dp50117.FILENAME := txtYourFileName;
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • rtrammelrtrammel Member Posts: 5
    The dataport I am working with is an export only, and I have the Import property set to No and UseReqForm property set to Yes on the Report properties page. After your post I added the following code to the OnInitDataport trigger
    CurrDataport.IMPORT(FALSE);
    That did not solve the problem.
    When request form opens it is populated with all values passed to it from codeunit that called it, but user has to click OK button.
    I am trying to create a dataport that can be run both unattended from a codeunit that passes the needed values and by user that inputs needed values. And dataport knows when to display request form and when not to display request form.


    This is code from codeunit that calls dataport.
    OBJECT Codeunit 50068 RichardsTest
    {
      OBJECT-PROPERTIES
      {
        Date=12/31/09;
        Time=[ 8:11:30 AM];
        Modified=Yes;
        Version List=RFT;
      }
      PROPERTIES
      {
        OnRun=BEGIN
    
                  DayNum := DATE2DMY(TODAY,1);
    
                  First := CALCDATE('CM-CM');
                  Last := CALCDATE('CD-1D');
                  IF DayNum = 1 THEN
                    BEGIN
                     First := CALCDATE('CM-CM-1D-1M+1D');
                     Last := CALCDATE('CM-CM-1D');
                    END;
    
                  CLEAR(dp50117);
                  dp50117.SetVariables('002','A0422', First, Last);
                  //dp50117.USEREQUESTFORM := FALSE;
                  dp50117.RUN;
    
    
              END;
    
      }
      CODE
      {
        VAR
          DayNum@1000000001 : Integer;
          First@1000000006 : Date;
          Last@1000000007 : Date;
          dp50117@1000000009 : Dataport 50117;
    
        BEGIN
        {
          *** Calls Dataport 50117 ***
        }
        END.
      }
    }
    
    

    This is code of dataport:
    OBJECT Dataport 50117 Test - Export Store Inv(50007)
    {
      OBJECT-PROPERTIES
      {
        Date=12/31/09;
        Time=[ 8:19:21 AM];
        Modified=Yes;
        Version List=;
      }
      PROPERTIES
      {
        Import=No;
        UseReqForm=Yes;
        OnInitDataport=BEGIN
                           //USEREQUESTFORM := bUseReqForm;
                           CurrDataport.IMPORT(bUseReqForm);
                       END;
    
        OnPreDataport=BEGIN
                          IF COPYSTR(tPath, STRLEN(tPath),1) <> '\' THEN
                            tPath := tPath + '\';
                          CurrDataport.FILENAME := tPath + 'StoreInv-' + cStoreFilter + '.Txt';
                      END;
    
      }
      DATAITEMS
      {
        { PROPERTIES
          {
            DataItemTable=Table50007;
            DataItemTableView=SORTING(Customer No.,Item No.,Inventory Date)
                              ORDER(Ascending);
            OnPreDataItem=BEGIN
                              IF FORMAT(dBegDate) <> '' THEN
                                iDateTest := 1;
                              IF FORMAT(dEndDate) <> '' THEN
                                iDateTest := iDateTest + 2;
    
                              CASE iDateTest OF
                                1: "Monthly Store Inventory".SETFILTER("Monthly Store Inventory"."Inventory Date", '%1',dBegDate);
                                2: "Monthly Store Inventory".SETFILTER("Monthly Store Inventory"."Inventory Date", '%1',dEndDate);
                                3: "Monthly Store Inventory".SETFILTER("Monthly Store Inventory"."Inventory Date", '%1..%2',dBegDate,dEndDate);
                              ELSE
                              END;
                              "Monthly Store Inventory".SETFILTER("Monthly Store Inventory"."Customer No.", cStoreFilter);
                              "Monthly Store Inventory".SETFILTER("Monthly Store Inventory"."Item No.", cItemFilter);
                          END;
    
          }
          FIELDS
          {
            { 1    ;10   ;"Customer No."       }
            { 12   ;10   ;"Item No."           }
            { 23   ;11   ;"Inventory Date"     }
            { 35   ;12   ;"Item Quantity"      }
            { 48   ;12   ;"Item Price"         }
          }
           }
      }
      REQUESTFORM
      {
        PROPERTIES
        {
          Width=13310;
          Height=6490;
          OnOpenForm=BEGIN
                       tPath := 'C:\Windows\Temp\';
                     END;
    
        }
        CONTROLS
        {
          { 1000000000;TextBox;5170 ;880  ;2310 ;440  ;SourceExpr=cStoreFilter }
          { 1000000001;Label  ;1760 ;880  ;3300 ;440  ;ParentControl=1000000000;
                                                       CaptionML=ENU=Store No. }
          { 1000000002;TextBox;5170 ;1760 ;2310 ;440  ;SourceExpr=cItemFilter }
          { 1000000003;Label  ;1760 ;1760 ;3300 ;440  ;ParentControl=1000000002;
                                                       CaptionML=ENU=Item No. }
          { 1000000004;TextBox;5170 ;2640 ;2310 ;440  ;SourceExpr=dBegDate }
          { 1000000005;Label  ;1760 ;2640 ;3300 ;440  ;ParentControl=1000000004;
                                                       CaptionML=ENU=Start Date }
          { 1000000006;TextBox;5170 ;3520 ;2310 ;440  ;SourceExpr=dEndDate }
          { 1000000007;Label  ;1760 ;3520 ;3300 ;440  ;ParentControl=1000000006;
                                                       CaptionML=ENU=End Date }
          { 1000000008;TextBox;5170 ;4400 ;7040 ;440  ;SourceExpr=tPath }
          { 1000000009;Label  ;1760 ;4400 ;3300 ;440  ;ParentControl=1000000008;
                                                       CaptionML=ENU=File Path }
        }
      }
      CODE
      {
        VAR
          cStoreFilter@1000000000 : Code[10];
          cItemFilter@1000000001 : Code[10];
          tDateFilter@1000000002 : Text[30];
          dBegDate@1000000003 : Date;
          dEndDate@1000000004 : Date;
          iDateTest@1000000005 : Integer;
          tPath@1000000006 : Text[250];
          bUseReqForm@1000000007 : Boolean;
    
        PROCEDURE SetVariables@1000000001(StoreNo@1000000000 : Code[10];ItemNo@1000000001 : Code[10];BegDate@1000000002 : Date;EndDate@1000000003 : Date);
        BEGIN
            cStoreFilter := StoreNo;
            cItemFilter  := ItemNo;
            dBegDate     := BegDate;
            dEndDate     := EndDate;
            tPath        := 'C:\Windows\Temp\';
            bUseReqForm  := FALSE;
        END;
    
        BEGIN
        END.
      }
    }
    
    


    Any and all suggestions welcome.
    Navision - ver. NA 4.00 (4.0 SP2)
  • lvanvugtlvanvugt Member Posts: 774
    Why not use the DATAPORT.RUN(Number [, ReqWindow] [, Record]) method?
    The pnly thing you need to provide by code is the path of the file.
    Luc van Vugt, fluxxus.nl
    Never stop learning
    Van Vugt's dynamiXs
    Dutch Dynamics Community
  • rtrammelrtrammel Member Posts: 5
    When I attempt to use Dataport.Run method, parameters passed in statement
    dp50117.SetVariables('002','A0422', First, Last);
    are lost. Variable name dp50117 , does not equate to Dataport(50117, FALSE). It is as if I am two different dataports.
    Navision - ver. NA 4.00 (4.0 SP2)
  • hawkeyehawkeye Member Posts: 51
    I have the exact same problem.

    I want the dataport to be runned with the requestform, when it is triggered maually, but when runned from a CU I want to put in parameters and run it without the requestform. (one of the parameters is filename)

    Did you find a solution?
  • tmontaguetmontague Member Posts: 2
    I'm having the same issue as well. We are running a 4.0 SP3 DB with the 5.0 Executable on the Native DB Server. When using the C/AL Symbol Menu, I can not find the USEREQUESTFORM Property or Function for a Dataport variable. When I have a USEREQESTFORM line, with or without a variable before it (USEREQUESTFORM vs Dataport.USEREQUESTFORM), I get the error:

    Microsoft Dynamics NAV
    You have specified an unknown variable.

    USEREQUESTFORM

    Define the variable under 'Global C/AL symbols'.

    OK
    Even the C/SIDE Reference Guide states the usage as [IsUseRequestForm] := USEREQUESTFORM([SetUseRequestForm]). Does anyone have any ideas as to why? Could it be that it's not supported in this version? Or the Native DB Server?
  • tmontaguetmontague Member Posts: 2
    I just noticed that USEREQUESTFORM Property is available on Forms! If you have a Report or Dataport variable on a Form, you can access the USEREQUESTFORM Property. Not sure why that wouldn't be available on a Report but it looks like it's not supported to be set from a Report's code.
  • rdebathrdebath Member Posts: 383
    I'm pretty sure USEREQUESTFORM has never been there, I guess it's a mistke in the documentation where it's been copy-pasted from the Report bit.

    Here's how you can do it though.

    prec is a Record::"370"
    prec.setrange(formula, '');
    prec.setrange(formula3, 'there');
    prec.setrange(formula2, 'hello');
    dataport.runmodal(dataport::"processing dataport", false, prec);
    
    OBJECT Dataport 123456798 Processing Dataport
    {
      OBJECT-PROPERTIES
      {
        Date=21/03/10;
        Time=17:00:18;
        Modified=Yes;
        Version List=;
      }
      PROPERTIES
      {
        Import=No;
        FieldStartDelimiter=<None>;
        FieldEndDelimiter=<None>;
        FieldSeparator=<TAB>;
        ShowStatus=No;
        OnPreDataport=BEGIN
                        StartedAt := CURRENTDATETIME;
                        CurrFile.CREATETEMPFILE;
                      END;
    
        OnPostDataport=BEGIN
                         MESSAGE('Dataport run Time %1', CURRENTDATETIME-StartedAt);
                       END;
    
      }
      DATAITEMS
      {
        { PROPERTIES
          {
            DataItemTable=Table370;
            DataItemTableView=SORTING(Row No.,Column No.);
            OnPreDataItem=BEGIN
                            IF GETFILTER(Formula) <> '' THEN
                              MESSAGE('Values: %1, %2, %3',
                                GETRANGEMIN(Formula),
                                GETRANGEMIN(Formula2),
                                GETRANGEMIN(Formula3)
                              );
                            CurrDataport.BREAK;
                          END;
    
          }
          FIELDS
          {
          }
           }
        { PROPERTIES
          {
            DataItemTable=Table18;
          }
          FIELDS
          {
          }
           }
      }
      REQUESTFORM
      {
        PROPERTIES
        {
          Width=9020;
          Height=3410;
        }
        CONTROLS
        {
          { 1   ;TextBox      ;3630 ;110  ;5170 ;440  ;HorzGlue=Both;
                                                       AssistEdit=Yes;
                                                       SourceExpr=Filename }
          { 1000000001;Label  ;220  ;110  ;3300 ;440  ;ParentControl=1 }
        }
      }
      CODE
      {
        VAR
          Filename@1000000000 : Text[1024];
          StartedAt@1000000004 : DateTime;
    
        BEGIN
        END.
      }
    }
    
Sign In or Register to comment.