10 Replies Latest reply on Sep 27, 2012 11:59 AM by DavidF

    Scripting - Export Field Contents Problem

    DavidF

      Title

      Scripting - Export Field Contents Problem

      Post

           Hello,
           I would be greatful for some help in spotting the obvious? mistake in my FMP 12 script.
           From a found set of records, I need to extract,the text from a text field called "Notesp01" and write its contents to a .txt file. Each .txt file is  to be named with the contents of a text field called "doc_ref_no".
           So if I have found 10 records I need to end up with 10 off .txt files each named as per the contents of "doc-ref_no" i.e tda123456.txt, tda15697.txt ......etc. All text files to be stored in same folder.
           The following script  only half works. Instead of getting 10 off indivdually named files I get 1 file written to 10 times- the resulting file being called $fiilename.
           I am new to the world of FMP variables, I think its a  variable problem, but I dont understand why its not working
           Any help with  this would be very welcome
            
           Regards

           Dfred

            
           script
           Go to Record/Request/Page[ First ]
           Loop
           Set Variable [ $filename; Value:(TDA::doc_ref_no)&".txt" ]
           Export Field Contents [ TDA::Notesp01; “file:../../38 Projects/TDA 2nd pass/$fiilename” ]
           Go to Record/Request/Page
           [ Next; Exit after last ]
           End Loop
            
           output path
           file:../../38 Projects/TDA  2nd pass/$fiilename

        • 1. Re: Scripting - Export Field Contents Problem
          philmodjunk

               Use:

               Set Variable [ $filename; Value:“file:../../38 Projects/TDA 2nd pass/" & TDA::doc_ref_no &".txt" ]
               Export Field Contents [ TDA::Notesp01; $filename ]
          • 2. Re: Scripting - Export Field Contents Problem
            DavidF

                  

                 Thanks for the prompt reply.

                 I have made the changes you suggested - now my script and your tweakes look to be the same but still I get 1 file "$filename" written 10 times and not 10 x files. The loop appears to be looping and writing but the file creation element seems not to be working. Its strange

                  

                 Regards

                  

            • 3. Re: Scripting - Export Field Contents Problem
              philmodjunk

                   Check for  quotation marks inside the Specify Output File dialog box. If there are quotes around $FileName, they are the source of your trouble and they need to be removed.

              • 4. Re: Scripting - Export Field Contents Problem
                DavidF

                      

                     Hi
                     The Specify Output File dialog box. does  not have quotes around $FileName. However the script screen does show  "$filename" . The quotes are seemingly added automatically and there is no direct way, or I cannot see a direct way, to remove them.
                      
                     Regards
                • 5. Re: Scripting - Export Field Contents Problem
                  philmodjunk

                       That then shows correct syntax. If the script editor showed ""$filename"" then you'd know that you had quotes in the specify output file dialog that shouldn't be there.

                       From here, I can't see exactly why you are getting "$filename" as the actual name of the file.

                       Two things I would check if I were you:

                       I'd use the data viewer and script debugger to check to see what value is being set to $filename in the script and what value is being returned by TDA::doc_ref_no. If you don't have FileMaker Advanced, you can use a Show Custom Dialog placed just before the Export Field Contents step to check the values that way.

                       I'd delete all files from the folder to which the script is exporting text files before running the script again, just to make sure that I am not confusing files created by an earlier run of the script with the files created by this run.

                       If all else fails, you could post your complete script.

                       To post a script to the forum:

                         
                  1.           You can upload a screen shot of your script by using the Upload an Image controls located just below Post A Answer.
                  2.      
                  3.           You can print a script to a PDF, open the PDF and then select and copy the script as text from the opened PDF to your clipboard for pasting here.
                  4.      
                  5.           If You have FileMaker Advanced, you can generate a database design report and copy the script as text from there.
                  6.      
                  7.           If you paste a text form of the script, you can use the Script Pretty box in the Known Bugs List database to paste a version that is single spaced and indented for a more professional and easier to read format. (Use the HTML option on the database tab panel and paste the text into the forum's HTML editor.)
                  • 6. Re: Scripting - Export Field Contents Problem
                    DavidF

                          

                         Hello,

                         I dont have FM Advanced.But I did add a Show Custom Dialog event before Export Field contents event in the script.

                         I stepped through the script which passed correctly each doc_ref_no file name in sequence and stopped after the number of found records. As usual I ended up with a single file called $filename.

                         I attach a screen grab of the script. Thanks for your help with this 

                         DavidF

                          

                          

                    • 7. Re: Scripting - Export Field Contents Problem
                      philmodjunk

                           Aha!

                           Note that you have misspelled the variable name in the Export Field Contents step. You have an extra "i" in there.

                      • 8. Re: Scripting - Export Field Contents Problem
                        DavidF

                              

                                       Doh,
                                       Thats what happens if you stare at a screen all day. Note to self - get eyes checked.
                                       Thanks for spotting that- we are perilously close to the script working, however FMP is not letting me off hook yet.
                                       Made the change (deleted extra i) and kept the Show Custom Dialog in place ran the script and at each file name I got tan   error message -see below. Interestingly no file of any name was written to the target folder which is indicativa that variable/loop  is working. Its just the file creation/writing thats not.
                                        
                                       I am using a bog standard Mac Mini 2.4 GHz Intel Core 2 Duo  with 8 GB RAM and 213GB free space. It is running the  latest update to FMP12. Problem is I need the name format (whole point of exercise), there is lots (and lots) of space on the HD,  the HD is not locked- or if it is , it  has  happily had files written to it nearly every day for 2 years and I dont really want to get another disk- but might have to.
                                        
                                       Last(ish) question=  What do you make of the error message?
                                        
                                       Thanks  your for your help once again
                                        
                                       DavidF
                                   
                                   
                                   
                                   
                                   
                              
                        • 9. Re: Scripting - Export Field Contents Problem
                          philmodjunk

                               That particular error message is one of the more misleading ones in Filemaker. It only means: "I couldn't create the file". It doesn't know which issue was the actual cause and those listed are not the most likely culprits.

                               An invalid filename--one with characters that can't be used in af file name, will trigger this error.

                               An invalid file path--the number one source of this error in my experience

                               Lack of room on the hard drive

                               A location where "write" permission is not permitted for the current user

                               All can trip this message.

                               I don't think a file path with ../.../ will evaluate correctly here. I believe that you need to use the "fully qualified" file path instead.

                          • 10. Re: Scripting - Export Field Contents Problem
                            DavidF

                                  

                                 Hi,
                                 As you predicted a fully qualified file path fixed the problem.
                                 I really appreciate the the help.
                                  
                                 Regards
                                  
                                  
                                 DavidF