Running A Dataport Into A Codeunit

MoonspellheimMoonspellheim Member Posts: 8
Hi!Does anybody know how can I manage to run a dataport inside a codeunit without having to fill the form?For example,if I want to use a specific dataport inside a LOOP statement?

Comments

  • kinekine Member Posts: 12,562
    You need to call the dataport without request form (second param in DATAPORT.RUNMODAL) and add some function into dataport, which will set the FileName to apropriate value...

    You need something like this in OnPreDataport trigger:
    CurrDataport.FILENAME(InputFile);
    
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • MoonspellheimMoonspellheim Member Posts: 8
    And how can I set a value in the Inputfile from the codeunit???
    (If this question is too stupid,SORRY I am a beginner!!! :cry: )
  • kinekine Member Posts: 12,562
    I do not know stupid questions, I know only stupid answers... :-)

    Of course you can pass values in same way as into report etc. Define the dataport as variable, create some function in the dataport, call this function from the CU and pass the value, then call RUNMODAL on this dataport variable.

    Or there is another way: define it as variable, this variable has property FILENAME - set it for the file name. Then run the dataport (DataPortVar is var of type Dataport and subtype your dataport you want to run):
      DataPortVar.FILENAME := 'my:\\filename.txt';
      DataPortVar.IMPORT := true; //if you want import
      DataPortVar.RUNMODAL; 
    
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • MoonspellheimMoonspellheim Member Posts: 8
    Hi again!
    When I try the first way I get the message:"Dataport 0 does not exist".
    When I try the second way I have to fill the form.
    Do you have any idea what can I possibly be doing wrong???
  • kinekine Member Posts: 12,562
    When I try the first way I get the message:"Dataport 0 does not exist".

    You didn't define which dataport you want to run... :-)

    In second case, you need to disable Request Form (UseReqForm property on Dataport).
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • MoonspellheimMoonspellheim Member Posts: 8
    You are so the man!!!I wish I was able to pay you back!!!
  • kinekine Member Posts: 12,562
    Helping you is my pleasure... :-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.