Export CSV - Delete file when Error Processing

nickrobbo89nickrobbo89 Member Posts: 10
edited 2015-08-28 in NAV Three Tier
Hello Everyone,

We have a Job Queue Entry which runs and exports a CSV file, if it fails the job queue entry errors but the file it has created stays in the specified folder location, obviously this is bad as next time it runs it picks up some of the entries placed in the previous file, files are sent to the external vendor and obviously they are not happy to receive these duplicates.

I want to know if it is possible to delete the file if the job queue errors at all?

Note - the job queue was not designed by myself and is not using an XML port to export the data. :roll:

Comments

  • mrealm1mrealm1 Member Posts: 15
    Hi,
    Without coding? No.

    You may want to adjust the process to delete/archive any existing files at the beginning of the routine (clear out left over files) or change the structure of the routine to verify the process ran (i.e. if Codeunit.run) and delete any existing files if not.

    I'd stay away from modifying the JobQueue processing as it would be something specific to the job and not the platform.
  • nickrobbo89nickrobbo89 Member Posts: 10
    Thanks for the feedback, I will try that. We pass in a record to the Code Unit and create the file, and then after the file is created or the record is added to the existing file, we mark the record as Processed, so I have added a COMMIT after this, so if it falls back at least the records in the created file will not be picked up the next time the Job Queue runs. I like you're idea of clearing out the folder before the job queue runs as well, thanks.
  • vaprogvaprog Member Posts: 1,140
    Write your output to a temporary file first. Preferably use a file marked as temporary for that purpose. Files with the Temporary attribute set will be deleted automatically after the handle is closed. CREATETEMPFILE uses that system service. You either need to find a way to remove that attribute from that file and move/rename the file in the end, or instead copy it's contents to the final destination after all else is done.
    You might also consider using Dotnet to handle your file creation and IO.
Sign In or Register to comment.