Code to export to a file to a specified folder with a specific file name e.g. ClientNameDateTime

Hi,

I am trying to write some code to include in an export dataport that would set the folder location and a variable file name e.g. C:\TEMP\ClientNameDateTime?

I have also been led to believe by my vendor that Nav does not have a scheduler? Is this true? Are there any addons? What do other people do?

Any help is most appreciated.

Regards, Sue

I am Nav 4.0 user.

The Job Scheduler relative tables are #5980~#5982. To run Job Scheduler, it need one user login Nav and keep it running it 7-24 therefore it will occupy one user license. If you purchase the Service granules then you shall able to run the job scheduler. I am not sure you can purhcase granules for only job scheduler relative tables & forms.

Sue, instead of hard coding the path and file, add a field to a setup table, and program the dataport to retrieve it from there. That way, a user can change the default path/file without having to change the design of the object.

Den,

Thanks for the suggestion.

I have finally got back to this. I created a new field to hold the path & am trying to copy some code to create a variable name. I think I have it.

DateTimeText := FORMAT(TODAY,0,’<Month,2><Day,2>’) + ‘_’ +
FORMAT(TIME,0,’<Minutes,2><Seconds,2>’);

OutFile.CREATE(CompInfo.“ECN File Location” + ‘’ + DateTimeText + ‘ECN_Customer.csv’);

However, how do I then get the dataport to write to this file? Do I need to pass every record to a new field and then WRITE these fields to the file? Can I not just point the dataport to this new variable (in properties)?

Sorry, I am no developer (as you can see) and have a very limited budget - so can’t get my vendor to help as they would consider this consulting.

I am very frustrated as I used another ERP system and this was the easiest thing in the world - no development required! It also had an inbuilt easy to use scheduler.

Sue

Hi Sue,

This is a easy task.

  1. Modify the dataport to set the UseReqForm to “No”.

  2. Declare a variable of type Dataport and point to the dataport.

samples code:

MyDataport.IMPORT := false;

MyDataport.FILENAME := CompInfo.“ECN File Location” + ‘’ + DateTimeText + ‘ECN_Customer.csv’; // From your code

MyDataport.RUNMODAL;

You can also set the table view to use by

MyDataport.SETTABLEVIEW( MyRec );

Hi Dave,

Thanks for getting back to me. I have finally cracked it. Your code snippet pointed me in the right direction. I am forever grateful.

I ended up added the following code to the OnInitDataPort() -

CompInfo.GET(CompInfo.“ECN File Location”);

DateText := FORMAT(TODAY,0,’<Month,2><Day,2>’);

CurrFile.QUERYREPLACE(FALSE);
OutFileName := CompInfo.“ECN File Location” + ‘’ + DateText + ‘_’ + CompInfo.“Abbreviated Name” + ‘_Customer.csv’;

CurrDataport.FILENAME(OutFileName)

Sue