Passing a Temporary Record to/from a Dataport?

Joe_CoolJoe_Cool Member Posts: 7
edited 2011-06-21 in NAV Tips & Tricks
Hello Everyone,
I was wondering if you can pass a temporary table to a dataport for export.

I have tried it by including the following line in a codeunit that contain a function that populates the temp table with the desired records;
DATAPORT.RUNMODAL(50066,TRUE,gtbUNIINSmallParcel);

but I get an error message when it tried to execute telling me that the dataport does not have a DataItem that uses the table specified in the function SetTableView.
The Dataport has the table listed in the dataitem and it is the same table the temp record is based on.

So why am I getting this error? Can this even be done? I am trying to do with through a temp table so that I do not have to create a new table that is similar to one that I have already created that has the fields that I need. I know that I can use variables in the dataport to include values contained in various tables, but that would mean that I would have to use coded logic to filter the records rather than true filters and therefore would have to scan the entire table everytime I run the report.

If remove the temp table from the RUNMODAL command there is no error (but the dataport uses the data that is in the table - Obviously).

Joe
P.S. I know that isn't the Canadian flag... I just thought I would use my Ethnic flag instead of my residence flag.

Answers

  • David_CoxDavid_Cox Member Posts: 509
    you will have to pass in the recordset and populate the export from the passed in table.

    I would use an integer and variables to export
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • Joe_CoolJoe_Cool Member Posts: 7
    David Cox wrote:
    you will have to pass in the recordset and populate the export from the passed in table.

    I would use an integer and variables to export

    Thanks for the reply, but I don't understand what you are saying.
    I guess that I should have mentioned that I am a Navision Newbie.
    I thought I was passing the recordset in the RUNMODAL command.

    gtbUNIINSmallParcel = the Temp Record that is populated in the Codeunit.
    50066 = the Dataport.
  • krikikriki Member, Moderator Posts: 9,112
    In the dataport, you need to make a global record variable "tmpTheTempTable" as temptable (property Temptable=Yes).
    The dataitem of your dataport must work on the virtual table integer. In the dataportfields, you have to put the fields of the temptable.
    You need a function in your dataport to fill up the temptable. Something like:
    Function ImportTempTable (VAR ItmpTheTempTable : as temptable)
    ItmpTheTempTable.RESET;
    IF ItmpTheTempTable.FIND('-') THEN
      REPEAT
        tmpTheTempTable := ItmpTheTempTable;
        tmpTheTempTable.INSERT(FALSE);
      UNTIL ItmpTheTempTable.NEXT = 0;
    

    In the OnPreDataItem-trigger:
    tmpTheTempTable.RESET;
    SETRANGE(Number,1,tmpTheTempTable.COUNT);
    

    In the OnBeforeExportRecord-trigger:
    IF Number = 1 THEN
      tmpTheTempTable.FIND('-')
    ELSE
      tmpTheTempTable.NEXT;
    


    In the calling program:
    Make a global variable for the dataport
    For calling the dataport:
    CLEAR(dtpYourDataport);
    dtpYourDataport.ImportTempTable(tmpTheTempTable);
    dtpYourDataport.RUNMODAL;
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Joe_CoolJoe_Cool Member Posts: 7
    Thanks.
    I didn't know that you could set a DataItem entered as Integer and what that did. Once I figured that out, I realized that I could contain all the code and the temporay table within the dataport.

    Joe 8)
  • ASTAST Member Posts: 108
    What about import to temporary table? What is the trick?
  • krikikriki Member, Moderator Posts: 9,112
    AST wrote:
    What about import to temporary table? What is the trick?
    Less or more the same.
    You put the table on which your temptable is based in the dataitem with properties AutoSave,AutoUpdate,AutoReplace = No.

    global:
    tmpTheTable as TEMPORARY record

    OnBeforeImportRecord-trigger:
    CLEAR("The Table");
    

    OnAfterImportRecord-trigger:
    tmpTheTable := "The Table";
    tmpTheTable.INSERT(FALSE);
    

    This function must be called after launching the dataport:
    Function ExportTempTable (VAR OtmpTheTempTable : as temptable)
    OtmpTheTempTable.RESET;
    OtmpTheTempTable.DELETEALL(FALSE);
    
    tmpTheTable.RESET;
    IF tmpTheTable.FIND('-') THEN
      REPEAT
        OtmpTheTempTable := tmpTheTable;
        OtmpTheTempTable.INSERT(FALSE);
      UNTIL tmpTheTable.NEXT = 0;
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • krikikriki Member, Moderator Posts: 9,112
    [Topic moved from Navision Attain forum to Navision Tips & Tricks forum]
    [Changed the title from "[SOLVED] Passing a Temporary Record to a Dataport?" to "[SOLVED] Passing a Temporary Record to/from a Dataport?"]
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Ravi_ThakkarRavi_Thakkar Member Posts: 392
    Hello Kriki,

    Thanks for your great Tip regarding "Import Data in Temporary Table through Dataport".
    I have did the code as you have suggested for the same task.

    I wrote one codeunit as below.
    OnRun()
    LocationDtp.RUNMODAL;
    LocationDtp.ExportTempTable(LocationTmpTable);
    LocationListFrm.SETTABLEVIEW(LocationTmpTable);
    LocationListFrm.RUNMODAL;
    

    Where variables are:
    LocationDtp-Dataport-Location
    LocationListFrm-Form-Location List
    LocationTmpTable-Record-Location-Temporary=yes.

    Dataport "Location" with properties AutoSave,AutoUpdate,AutoReplace = No.
    having code as:
    Documentation()
    Location - OnPreDataItem()
    Location - OnBeforeExportRecord()
    Location - OnAfterExportRecord()
    Location - OnBeforeImportRecord()
    CLEAR(Location);
    
    Location - OnAfterImportRecord()
    LocTmp := Location;
    LocTmp.INSERT(FALSE);
    
    Location - OnPostDataItem()
    
    ExportTempTable(VAR OtmpTheTempTable : TEMPORARY Record Location)OtmpTheTempTable.RESET;
    OtmpTheTempTable.DELETEALL(FALSE);
    
    LocTmp.RESET;
    IF LocTmp.FIND('-') THEN
      REPEAT
        OtmpTheTempTable := LocTmp;
        OtmpTheTempTable.INSERT(FALSE);
      UNTIL LocTmp.NEXT = 0;
    

    Where variables are:
    Parameters of ExportTempTable Function:
    Var-Name-DataType-Subtype
    Yes-OtmpTheTempTable-Record-Location

    Global Variables:
    Name-DataType-Subtype
    LocTmp-Record-Location
    LocationListFrm-Form-Location List

    After I run the Codeunit, it is now viewing the Temporary Table Data in the form.
    It is working fine now.

    Thanks for sharing such a gr8 tip.
    Ravi_Thakkar
    Ahmedabad, Gujarat, India
    E Mail : ravi.thakkar@hotmail.com
  • krikikriki Member, Moderator Posts: 9,112
    It's nice to see that my tips are put to good use! :D
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Ravi_ThakkarRavi_Thakkar Member Posts: 392
    True Kriki.

    I am having an issue in the same method with the XML PORT in RTC.

    ExportTempTable returns Blank table from the XML PORT.

    I think XMLport does not run Modally, and that's why I am facing the issue.
    Any suggestion regarding the same?
    Ravi_Thakkar
    Ahmedabad, Gujarat, India
    E Mail : ravi.thakkar@hotmail.com
  • krikikriki Member, Moderator Posts: 9,112
    Have you tried the XML-port with a classic client? Just to be sure it is a RTC problem and not something else.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • BeliasBelias Member Posts: 2,998
    i just made a test xmlport (used as dataport) (--> sorry, it is a real xmlport, not an xmlport as dataport) that works like a charm, using the temporary property of the table element.
    I did it while testing webservices and see where i can go
    OBJECT XMLport 50600 xmlwebservice
    {
      OBJECT-PROPERTIES
      {
        Date=20/06/11;
        Time=17.55.33;
        Modified=Yes;
        Version List=;
      }
      PROPERTIES
      {
        UseDefaultNamespace=Yes;
        OnPostXMLport=BEGIN
                        ERROR(FORMAT(Location.COUNT));
                      END;
    
      }
      ELEMENTS
      {
        { [{80D3A770-4659-442E-890D-16964E055A84}];  ;RootLocation        ;Element ;Text    ;
                                                      MaxOccurs=Once }
    
        { [{E06FC085-52D9-4301-A107-15DC5822CD34}];1 ;Location            ;Element ;Table   ;
                                                      SourceTable=Table14;
                                                      Temporary=Yes }
    
        { [{9E0DD462-6DDC-4D68-9435-BDC5FBE21631}];2 ;Code                ;Element ;Field   ;
                                                      DataType=Code;
                                                      SourceField=Location::Code }
    
        { [{A921CED9-96DF-4FD3-A6AD-8C12D2A114C6}];2 ;Name                ;Element ;Field   ;
                                                      DataType=Text;
                                                      SourceField=Location::Name }
    
      }
      EVENTS
      {
      }
      REQUESTPAGE
      {
        PROPERTIES
        {
        }
        CONTROLS
        {
        }
      }
      CODE
      {
    
        BEGIN
        END.
      }
    }
    
    
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
Sign In or Register to comment.