5 Replies Latest reply on Jan 31, 2017 1:59 PM by philmodjunk

    Script Problem when opening File

    andrewma

      I have a Main database that I am trying to import data to from another one.

       

      Database A  has a button that when pressed is supposed to open Database B.

      When Database B is opened(preferrable hidden) I want a script to run.  After the script runs, Database B can close

      (the script is one that collects data from an excel sheet)

       

      My problem is I have selected the script on Database B to run based on a script trigger "OnFirstWindowOpen".

      And it does not trigger when the file is simply opened.

       

      If I run it manually it works just fine.  It seems there is no way to have a script run when a file is opened, and then closed almost immediately and never actually having its window shown on my screen.

       

      Just to clarify, I do not want to see or even interact normally with  Database B, I simply want it to open, run the import script then close.

       

      That way I can have my field in Database A which is a Lookup of one in Database B show the data I'm looking for properly.

        • 1. Re: Script Problem when opening File
          philmodjunk

          Opening the file will trip the trigger and run the script, but maybe the file is already open and hidden at the time you click the button? there are a number of reasons why a file might be open in the background and closing it might not work as a reference in the first file might automatically re-open it in the background.

           

          A more reliable method, and one that can allow you to open File B without tripping the trigger should you need to--say to do some development work on the file, is to just set the script in File A to Perform the script in File B. No need to trip any script triggers to get this to happen then. This requires the same External Data Source Reference used by Open File so you should be able to just select File B then select the script in File B when setting up that Perform Script script step.

          • 2. Re: Script Problem when opening File
            andrewma

            I see the logic you are using, and you may very well be correct, Database B may very well be open in the background and hidden due to the fact that Database A has a field that does a look up into Database B.

             

            So the script in Database A, would that simply consist of the following line ?:

            Perform Script ["import" from file: "Database B"]

             

            Or would I have to add lines that Open and then close Database B in the script ?

             

            Here is an example of what is not working -

            Filemaker Pro completely shut down,  I open Database A but do not go to the layout with the field that does a lookup from Database B, (so I expect it will not open DB B in in the background).

            I then open Database B, it runs the import script as expected.

            I close DB B, and then go to DB A and go to the layout that has the field which does the lookup from DB B, and I run the script listed above, and DB B opens but DOES NOT run the import script!

             

            I am assuming this is because  even though I closed DB B, it was still left open somewhere in a hidden state and therefore not triggering the open script  ??

             

             

             

             

            Sidenote. is there any way to know or show a database that is opened but not showing in the list of opened Databases under the "Windows" Menu ?

            • 3. Re: Script Problem when opening File
              philmodjunk

              You just need that one perform script step.

              I close DB B, and then go to DB A and go to the layout that has the field which does the lookup from DB B,

              My guess is that this reopened DB B in the background and thus your Open File Script failed to work the way you wanted it to.

               

              I make it a practice to avoid, in nearly all cases, relying on one script tripping a script trigger to get something done. It's simpler and much safer just to perform the script in question. I add extra scripting to my scripts precisely to avoid such things as they result in brittle scripts where simply changing a layout--possibly months after setting the script up in the first place, breaks a script and you only find out that it failed when you spot incorrect results in your database due to the script failing.

              • 4. Re: Script Problem when opening File
                andrewma

                One rather possibly important piece of information that may or may not effect this is ,, both databases are hosted with Filemaker Server,, I suspect that is not the cause of any problem I hope ?

                • 5. Re: Script Problem when opening File
                  philmodjunk

                  Not that I can see from here, but my "view" is quite limited.