Dataport Export : How to change filename at runtime?

Saint-Sage
Saint-Sage Member Posts: 92
Hello Everyone,

I have a dataport which is supposed to run 4 times a day. The script that will pick up the file expects it to be labeled incrementally. Is there any way to do this with navision dataports? I.E. the first time it runs the file is NAV001.txt, the second time it should be NAV002.txt, etc....

Thanks in advance for any help you can give!

No one loves you like the one who created you...

Comments

  • jversusj
    jversusj Member Posts: 489
    You could do something like I did here, EDIFile2 is a record of type File:
    //Hardcode path to save output file.
    FilePath := '\\serverftp$\directory\subdirectory\';
    CLEAR(EDIFile2);
    EDIFile2.RESET;
    EDIFile2.SETRANGE(Path,FilePath);
    IF EDIFile2.FIND('-') THEN BEGIN  
       //found the path, now define the filename! 
       TempDate  := SIH.GETRANGEMIN("Posting Date");
       TempName := Text001 + FORMAT(TempDate,0,'<Month,2><Filler Character,0><Day,2><Filler Character,0><Year4>') + Text002;
       FileName := FilePath + TempName;
    

    where Text001 was a value and Text002 was the file extension (.txt). You would adjust the middle part to use incrementing integers if you didn't want the date.

    This would be on the PreDataport section. You should be able to simplify, since the above was written in a Report to get the Report to create a txt file for me. Maybe this can get you started?
    kind of fell into this...
  • Savatage
    Savatage Member Posts: 7,142
    How do you do it now?
    When you export are you manually creating the filename?
    You say Supposed to be run 4x a day - are they at set intervals?
    (ex. every 2 hours)

    and the next day it's stats again nav, nav2,nav3,nav4

    If it a time thing perhaps you can
    if between:
    8am - 10am then it will be Nav001.txt
    10:01am - 12pm = Nav002.txt
    etc

    but this doesn't insure that this will be correct - say you miss 8amto10am one. Does this cause a problem for you?
  • Alex_Chow
    Alex_Chow Member Posts: 5,063
    Saint-Sage wrote:
    Hello Everyone,

    I have a dataport which is supposed to run 4 times a day. The script that will pick up the file expects it to be labeled incrementally. Is there any way to do this with navision dataports? I.E. the first time it runs the file is NAV001.txt, the second time it should be NAV002.txt, etc....

    Thanks in advance for any help you can give!

    If the file increments the way you described, you can just create a new field to store the last filename it ran. Then all you would need to do when the process is ran the next time is to INCSTR (increment string) based on whatever the value of this field. :D
  • Saint-Sage
    Saint-Sage Member Posts: 92
    Thanks everyone for the help!

    JvsJ - That code is what I needed, particularly the FileName := blahblah, I needed to know what the property was called and where to change it beforehand. I had considered doing it in a report or codeunit, but as dataports make importing/exporting much quicker I didn't want to have to re-write the dataport as a report in order to get the functionality.

    Thanks go out to Savatage and deadlizard for the ideas on how to increment. All of you guys who post regularly and help us jr developers out are really helping Navision to move forward.

    Keep up the good work and thanks a bunch!

    No one loves you like the one who created you...
  • Saint-Sage
    Saint-Sage Member Posts: 92
    Hello Everyone,

    The fix did not work, there is no property relative to the dataport named

    FileName

    When you create a dataport there is a Property that you fill in with the file name. When you run the dataport it writes the data to that file. What I need is a property I can change at runtime based on the status of some previous field.

    For Instance :

    In OnInitDataport I would do...

    currentFileName := INCSTR(lastFileName);

    and it would write the file to the new filename instead of the one set in the default property.

    Is there any way to do this, or will I have to use a report or codeunit and actually write the values out?

    Thanks in advance...

    No one loves you like the one who created you...
  • Saint-Sage
    Saint-Sage Member Posts: 92
    Hello Everyone,

    A friend told me about a function called FILENAME(Dataport) you can use to dynamically set the filename. Thanks for everyone who tried to help, I don't know how to set this thing as solved!

    No one loves you like the one who created you...
  • jversusj
    jversusj Member Posts: 489
    Saint-Sage wrote:
    Hello Everyone,

    The fix did not work, there is no property relative to the dataport named

    FileName
    quote]

    Hi. I know this is solved, but wanted to clarify for anyone else trying to use this thread to meet a similar need. the variable "FileName" in my example was not a property, but a C/AL Global of Type 'Text 'and Length '250.' the example i wrote used a variable to pass a dynamic file name to export. glad you found an alternative.

    FYI, to mark solved, edit your first post and edit the thread subject to [solved]...
    kind of fell into this...