DATAPORT.RUN with function / Dynamic set dataport variable

raven44raven44 Member Posts: 85
Firstly, I suspect this can't be done BUT I'm hanging on the slightest chance of hope.

My scenario is:
I have the Object Type (Eg. dataport - which will be used to import) and Object ID in a table.
I want to run this dataport but set the filename from eg. another field in that table.
"Integer Value (PK)","Object Type", "Object ID", "Filename"
Within the dataport is a function to set the filename - but how can this function be called when using:
DATAPORT.RUN("Object ID",FALSE);

The only other alternative is having the ability to dynamically set a dataport variable - is this even possible?

Any ideas?
Thanks in advance.

Comments

  • MaximusMaximus Member Posts: 105
    Hi,

    don't use DATAPORT.RUN, but declare the Dataport as a global or local variable. Then you can access the functions that are in the dataport to set the filename.
  • kapamaroukapamarou Member Posts: 1,152
    You mean without declaring a separate variable for each dataport and without modifying all the dataports to set the filename?
  • garakgarak Member Posts: 3,263
    Sorry, with Dataport.run / runmodal you can not set the Filename (only Dataport - OnPreDataport() / Dataport - OnInitDataport()).
    But if your filename is dynamic you can set the dataport as variable and use the function filename. But with this you must every dataport set as variable.

    Or you store in your table where you also store the Dataport ID also the Dataportexport/ImportPath and in OnInitDataport() you read the rec and set the filename

    regards
    Do you make it right, it works too!
  • raven44raven44 Member Posts: 85
    I wouldn't be able to set the dataports as variables, as this would mean creating variables for many objects and if a new dataport got created - this would need to be set in the calling function. This is why I was wondering if we could dynamically set a dataport as a variable (during runtime.....somehow). We know the object type, we know the ID...but how to create a dynamic variable.

    Your second option is closer to what I was thinking, but if the user selects the same dataport for different records (due to the Primary Key) - then we wouldn't know what filename to use.

    Table Example:
    PK Type ID Filename
    1 Dataport 50000 C:\Cars
    2 Dataport 50001 C:\Boats
    3 Dataport 50000 C:\Cars (New Models)

    [I know the 'simple' answer would be PK = Integer, Type and ID - then create a [i]new [/i]dataport for [b]each [/b]one but where's the fun in that :wink: ]
  • DaveTDaveT Member Posts: 1,039
    Hi,

    Why not let the user select the filename in the form ans store it to the table, then the dataport can read the table to get the filename. Another option is to use a single instance codeunit and set/retreive the filename from it.
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
Sign In or Register to comment.