5 Replies Latest reply on Aug 29, 2011 9:52 AM by ijontichy

    Get the name of the file during import.

    RyanFishy

      Title

      Get the name of the file during import.

      Post

      FM Pro 11, Windows XP.

      I would like to try to record the source of some records created during a file import.  I need a way to store the file name (or  path) of a file being imported.  This could either be in a variable or a field.  I will be importing text or spreadsheet files.  These files will be chosen by the user manually at the time of import.  I can't figure out any way to do this.

      Thanks,

      Ryan

        • 1. Re: Get the name of the file during import.
          philmodjunk

          It's possibile to use Insert File with the store by reference option specified to insert a reference to the import file into a container field. You can then extract the file name from the container field and put it in a variable so that you can use it in the Import Records step and if you enable auto-entry options during import, the contents of this same variable can be auto-entered via an auto-entry calculation into a text field defined for this purpose.

          The script would look something like this:

          Set Error Capture [on]
          Insert File [Reference ; YourTable::YourcontainerField ]
          IF [ ( Get ( LastError ) = 0 ]
             Set Variable [$$Path ; GetValue ( YourTable::YourContainerField ; 2 )]
             Import Records [no dialog ; $$Path ; .....]
          End IF

          In the auto-enter calculation for your source field, you'd just use $$Path.

          When you run this script, you'll get an open file dialog where you can find and select the import file. The script will then use the reference (File path) to that file to import data from it and auto-enter that file path into the designated text field. If the user cancels the dialog, an error code is returned and no import takes place.

          Note:  when setting up the Import Records step, include two data source references like this:

          $$Path
          Sample file

          Where "Sample File" should be a specific literal reference to a file of the type from which you intend to import. That literal reference enables you to set up your field mapping, but when the script executes, it will give preference to $$Path over the literal reference so your user can select a file for import.

          • 2. Re: Get the name of the file during import.
            RyanFishy

            Worked like a charm, thanks again.

            -Ryan

            • 3. Re: Get the name of the file during import.
              ijontichy

              I tried this myself but could not get the name of the file to show up in a text field.   Any thoughts?   I set it up as Phil outlined it.   My file type is .edl.   Would that be a limiting factor?

              • 4. Re: Get the name of the file during import.
                philmodjunk

                If you can manually import from your .edl file, then this is not the issue. Check to make sure that you are using Insert File with the "store as reference" option enabled and make sure that the container field into which you are inserting this reference is physically present on the current layout when you do this.

                • 5. Re: Get the name of the file during import.
                  ijontichy

                  physically present in the current layout was it.   Thanks.