12 Replies Latest reply on Mar 9, 2016 10:01 AM by AlastairMcInnes

    GoTo Related Record in a script not working ?

    AlastairMcInnes

      I have two databases holding book data – one for print books, and the other for ebooks. They are currently related to each other via the print book ISBN which is also stored in the ebook database. The print database has an external table occurrence in it ,based on the ebook data table in the ebook database and I display the ISBN of the related ebook on a layout in the print database. I added a button setup to the ISBN field so that when you click on it, it opens the ebook database showing the correct record. It does this with a Go To Related Record call:

       

      Go to Related Record [ From table: “COB_Hardback”; External; Using layout: <Current Layout> ]

       

      This works perfectly.

       

      To make life easier, I added a button to the print database to create a new ebook record and populate it with the data that they share (title, authors, description and so on). To make this work, I created a layout in the print database based on the ebook table instance in the print database (the COB_Hardback referred to in the GTRR call above). Then I have these lines in a script:

       

      Go to Layout [ “COB_Hardback” (COB_Hardback) ]
      New Record/Request

       

      I have previously grabbed the common data into variables and I now copy the variables into the fields of the new (ebook) record.

      This all works perfectly. The record is created and populated in the ebook database.

       

      The script ends with a call to:

       

      Go to Layout [ original layout ]
      Refresh Window
      Go to Related Record [ From table: “COB_Hardback”; External; Using layout: <Current Layout> ]

       

      The intention is that the print database is returned to the layout it started on, but then the ebook database is opened and the new record displayed. The last line appears to be exactly the same as the button setup on the ebook ISBN field. The difference is that the button works and the script doesn’t.

       

      If I then click on the ISBN field, to call its button setup, the ebook database opens (or activates if already open) and shows the record.

       

      To test this further, I wrote a script with only the GTRR line in it and replaced the button setup of the ISBN field with a call to Perform Script with the name of my new script. It appears that the GTRR step only works if called directly from a button, and not as part of a script.

       

      Or have I missed something?

       

      This is in Filemaker 11 if it makes a difference, though I have tried it in FM12 with the same results.

       

      Many thanks in advance,

      Alastair

        • 1. Re: GoTo Related Record in a script not working ?
          schwjm

          What error code does the Go to Related Record step produce? (Either check Script Debugger or place a Show Custom Dialog [ Get(LastError) ] immediately after the GTRR step.)

          • 2. Re: GoTo Related Record in a script not working ?
            AlastairMcInnes

            Sorry, should have said. It doesn't produce an error. I ran it in the script debugger and it just runs the line with no error number produced.

            • 3. Re: GoTo Related Record in a script not working ?
              schwjm

              Regrettably, I am not too versed in using Go to Related Records using the Use External Table's Layouts option, or having user-interface layouts spanning across multiple files. However a quick test on my end shows that it behaves unlike I would expect. I set up a simple two file solution where books was in one file and ebooks was in another, related by a number field as you have.

               

              It seems that you are correct, that doing the GTRR as a direct button action causes the window to focus. If I put the same step in a script, it does in fact do the GTRR but does not focus the window. If the window wasn't open in the first place, it creates a hidden window that I can dig out of the Windows menu. Otherwise the GTRR is succeeding, except that it doesn't change what the current window is.

               

              I assume you're using this feature because you have a layout in the ebooks file you don't want to have two copies of between the two files. The quick fix may be to use a Select Window command. This will explicitly focus the window you want and that seemed to solve the issue for me. This will not work very well if you can't anticipate what the name of the window is, however.

              • 4. Re: GoTo Related Record in a script not working ?
                Mike_Mitchell

                AlastairMcInnes wrote:

                 

                It appears that the GTRR step only works if called directly from a button, and not as part of a script.

                 

                 

                That's definitely not true (I just updated a system and make extensive use of GTRR), so something else is going on. It's common practice to determine if the related record exists prior to calling the GTRR step. This is typically done by using:

                 

                     If [ not IsEmpty ( relatedTable::fieldThatAlwaysHasAValue ) ]

                 

                What happens if you do that?

                 

                Another issue is that, if you create a record in a related table (such as what you're doing), unless you commit the records, the related records may not show up. Are you sure the script is properly committing the record prior to trying to evaluate?

                • 5. Re: GoTo Related Record in a script not working ?
                  AlastairMcInnes

                  Hi Mike,

                   

                  There is a Commit Records/Requests script line immediately before the Go to Layout [ original layout ] step, so I assume it's committing OK.

                   

                  I created two text fields to display the ebook ISBN - one has a button setup calling the GTRR step directly, and the other's button setup calls a script whose sole line  is the GTRR call. The direct button works, and the script doesn't.

                   

                  I just amended the script to have an If line checking whether the ItemID (automatically filled with a serial number) is empty. It isn't.

                   

                  Thanks, though.

                  • 6. Re: GoTo Related Record in a script not working ?
                    AlastairMcInnes

                    Thanks for all that effort, Justin - I was just working on trying to put together a pair of databases to demonstrate the problem but you've beaten me to it.

                     

                    I've now created two fields to display the eBook ISBN in the print database. One has a button setup called GTRR directly, and the other calls a script containing the GTRR step.

                     

                    It doesn't seem to matter whether the eBook database is open or not - the direct button works and the script doesn't do anything at all. It doesn't open the eBook file (at least, it doesn't appear on the Windows menu). I'm not entirely clear how the Select Windows call would work, so can't check that.

                    • 7. Re: GoTo Related Record in a script not working ?
                      AlastairMcInnes

                      Hello again, Justin.

                       

                      I just realised that FM doesn't always add new windows to the Windows menu, but that doesn't stop me using Select Window to go to them. I've now managed to make the script work by adding a Select Window step too.

                       

                      Many thanks for the workaround.

                      • 8. Re: GoTo Related Record in a script not working ?
                        Mike_Mitchell

                        The behavior you're describing is inconsistent with my experience. Can you post your file?

                        • 9. Re: GoTo Related Record in a script not working ?
                          AlastairMcInnes

                          I haven't managed to make a working test setup as yet. Justin - if the files you have where you managed to show the same behaviour as I got are in an easily postable position, I'd be grateful if you could do that.

                           

                          Otherwise, I'll work on my test files and post them.

                           

                          Thanks.

                          • 10. Re: GoTo Related Record in a script not working ?
                            Mike_Mitchell

                            I just notice you're using "<Current layout>" on the GTRR step. Have you tried using the external file's layout?

                             

                            dialog.png

                            • 11. Re: GoTo Related Record in a script not working ?
                              Mike_Mitchell

                              You have to choose "new window" in the GTRR script step for this to work in a script, apparently. See attached.

                              • 12. Re: GoTo Related Record in a script not working ?
                                AlastairMcInnes

                                That's done it, Mike - thanks. I hadn't even noticed the option.

                                 

                                In answer to your previous point (now academic, I realise), I did try specifying a layout name, but it didn't make any difference so I took it out again.

                                 

                                Thanks to both of you for your time and help.

                                 

                                Alastair