2 Replies Latest reply on Jan 26, 2015 3:12 PM by philmodjunk

    export as individual records with unique file names... 23.csv, 24.csv, 25.csv, etc.

    dsmith99

      Title

      export as individual records with unique file names... 23.csv, 24.csv, 25.csv, etc.

      Post

      Hello FM Forum.

      I have a FM database of 1000 records, and will do a found set, and now have 200 records and each has a record number.

      I do not want to do one export and have a file with 200 records. I want a script that cycles through the 200 found set and does 200 separate exports to .CSV. As is, when you are done it will not work because the file name is "Untitled.csv" and it will want to overwrite each time.

      I want each individual export to end up in the same desktop folder and the script to auto-generate a unique file extension based on the record number within each record and use it in the file name.... record number115.CSV, so I will end up with 200 separate files, each with one record and named by the unique record number.

      Is this possible? I tried to use the set variable command before the export command but could not figure it out?

      Thanks, Doug in Los Angles

        • 1. Re: export as individual records with unique file names... 23.csv, 24.csv, 25.csv, etc.
          briancrockett

          You should be able to set a variable that uses a calculation to append the record number to the Filepath. "filewin:/A:/directoryname/" & table::record number & ".csv"

          The problem your going to have is "Export Records" will always export your entire found set. So stepping through all the records would result in 200 identical files that only vary by filename.

          I suggest using "Export Field Contents" instead. Then you can step through the found set exporting just a single field from a single record. To use it you'll have to create a calc field with all the fields you want to export and then export that field. 

          It would look something like this.

          "/"" & Field1 & "/"," & Field2 "/"," & Field3 "/""

          Some Gotcha's would be if a field already has a quote in it, it would screw up whatever app your importing these into. Depending on your app, carriage returns might also cause your import to fail. 

          You can use the "substitute" function to change quotes and carriage returns into something else that your app won't choke on.

          • 2. Re: export as individual records with unique file names... 23.csv, 24.csv, 25.csv, etc.
            philmodjunk

            Under some circumstances, export field contents may not produce the desired result. The exported data may not have the correct character set for what you need and you can't specify the character set with export field contents like you can with export records.

            Should that be the case, you can still export your individual records if you set up your scrip to produce single record found sets just before updating.