A tricky problem with the File system table...

davonessdavoness Member Posts: 22
I am having a problem with using the File record.

I have a report that is aiming to go through a certain folder and for each text file in that folder process it into Navision and archive it.

The report has one data item, of type File. This has the following Table View:

SORTING(Path,Is a file,Name) ORDER(Ascending) WHERE(Is a file=CONST(Yes))

OnPreDataItem I am setting a range on the folder based on a field on the Request form as follows

SETRANGE(Path,Filepath);

This works fine the first time it is run, however it is as if the values in the File table are cached - If the first run has archived all files out of the folder, on the second run it attempts to process the same files again. If I compile the report, the File variable seems to be 'refreshed' and it will correctly process nothing.

Also, if it is processed when there are no files in the source folder, and files are subsequently added, these are not picked up until I have compiled the report.

Is there a way to refresh the File table OnPreReport so that it provides an up-to date view? I have tried to RESET or CLEAR the variable, creating a second file variable and doing the same SETRANGE and then FIND('-') and FIND('+') and inserting a SLEEP(1) to give control back to the OS, none of which have worked. Any ideas would be appreciated.

Thanks

Comments

  • AlbertvhAlbertvh Member Posts: 516
    Hi

    Don't know if this will work but try using SELECTLATESTVERSION
    on InitReport
  • kinekine Member Posts: 12,562
    I had same problem. But now, I am using local variables where possible, calling Clear() before using, and it is working...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • davonessdavoness Member Posts: 22
    Thanks for the suggestion, unfortunately it didn't solve the problem, but I have found a solution.

    Inserting the following OnPreReport fixed the problem.

    CashReceiptFiles.SETRANGE(Path,ENVIRON('Temp'));
    IF CashReceiptFiles.FIND('-') THEN;

    If you set a range on a different directory it refreshes the list. ENVION('Temp') is all I could think of that would always exist (ie some citrix users may not have a c:\, but navision always has a temp folder)
  • DenSterDenSter Member Posts: 8,307
    That is a very annoying issue, and you have the only way to make that work. You have to reset the filter, get the content of that folder, and then reset it back and get the content again. It seems like the File virtual table is only able to get snapshots of file content.
  • markvandermeijmarkvandermeij Member Posts: 26
    Are you running the report directly from a menu? If you are, then try running it from another object (i.e. codeunit/report/form). I had the same problem running a piece of code using the FILE record. When I moved it to a report it ran without a problem.
  • chen_wanchen_wan Member Posts: 34
    Try to setrange to other file path before setrange to your intended path

    SETRANGE(Path, OtherPath);
    SETRANGE(Path,Filepath);
Sign In or Register to comment.