7 Replies Latest reply on Nov 10, 2014 8:59 AM by philmodjunk

    SetVariable works with GoToPortalRow but not for GTRR?!

    EmelieLeht

      Title

      SetVariable works with GoToPortalRow but not for GTRR?!

      Post

      I have tried both but they do not seem to work in the same way.

      I want to fetch data from a few fields in one (or several) related records.

      If I have these related records in a portal and in my script goes to one of the related records via GoToPortalRow; I can directly after use the SetVariable script step to get the data I want.

      If I instead use the GoToRelatedRecord, followed by GoToRecord to specify which one, the SetVariable script step wont load any data to the variable.
      The only way I got it to work with GTRR was to use GoToField[Select] and then use Get(ActiveFieldContents) to store the data in the variable.

      It does not make sense, it must be easier somehow, right?

      Best regards and thank you,
      Emelie

        • 1. Re: SetVariable works with GoToPortalRow but not for GTRR?!
          philmodjunk

          Sounds like you are either misspelling the name of the variable (a very easy mistake to make) or you have an incorrect field reference in your set variable script step. If you still cannot spot the error, you may want to post your precise script here so that others can take a look at it to help you spot the issue.

          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 New 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. (with this approach, you can get multiple script steps on the same line, please edit the pasted text by inserting some returns to separate those steps.)
          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.
          • 2. Re: SetVariable works with GoToPortalRow but not for GTRR?!
            EmelieLeht

            Ok, I think I actually solved this on my own. The issue was with the GTRR and several TO. It is not clear at all which way is the right way to go here.

            Let's call my table things, and things 2 is it's second TO. It has a layout Display things. The data I wanted to reach is data1.

            GTRR looked like this
            Go to related records; From table "things 2"; Using: Display things

            When I was using SetVariable I was calling the things 2 :: data1

            This just gave me an an empty variable but when I changed to

            things::data1

            I got the data I wanted.

            If you have an explation why it is this way I would be very gratful, I found it quite confusing :P

            Regards,

            Emelie 

             

            • 3. Re: SetVariable works with GoToPortalRow but not for GTRR?!
              philmodjunk

              Each layout specifies a particular table occurrence in layout setup in the "show records from" dialog. This establishes the "context" for how the relationships graph in manage database controls what data appears and is accessible on this layout.

              So if your layout specifies "Things" in show records from, a script that navigates to this layout should refer to "Things", not "Things 2". A reference to "Things 2" will be an attempt to use a relationship from "Things" to "Things 2" and that can return no data or very different data.

              For more about table occurrences, what they are and how to use them, see: Tutorial: What are Table Occurrences?

              Another "gotcha" to look out for here is if you specify a sort order for the portal. The order of the records pulled up by the GTRR won't automatically match the order of records in a sorted portal so you may need to include a sort records script step after the GTRR in order to make sure that Go to Record goes to the same record as you'd expect from your go to portal row script step.

              Caulkins Consulting, Home of Adventures In FileMaking

              • 4. Re: SetVariable works with GoToPortalRow but not for GTRR?!
                EmelieLeht

                I think I got the TOs right. I think it is rather the GTRR that is the spooky thing here. I looked at the layout and the "Display things" is indeed set to show records from "Things". Couldn't this layout still be used for showing records from "Things 2"? It is acutally working foor me somehow. I used the Pause script script step just after I called my GTRR to check. All the right records are there. I am not standing in a portal row or anything when I call GTRR. My aim is to reach "Things 2" to show the related records from this relationship and it actually works with the

                Go to related records; From table "Things 2"; Using: "Display things"(Things)

                I am not sure at all why, but it does work for me. No error messages or anything.

                What would the normal procedure be? To have a layout dedicated to show records from "Things 2" and use this in the GTRR step?

                Best regards,
                Emelie

                • 5. Re: SetVariable works with GoToPortalRow but not for GTRR?!
                  philmodjunk

                  Here's some key details on GTRR:

                  If there are no related records, GTRR with a specified layout (what you have here) will fail to do anything but silently return an error code. You'll still be on the same layout as before the GTRR and if you don't test for the existence of related records or the return of this error code, you script will continue to execute as though the GTRR was not part of your script, but now you are on a different layout and that can be disastrous in many cases.

                  GTRR uses the "table" designation (really should read "table occurrence") to determine what relationship from the current layout's table occurrence to this specified table occurrence to use to pull up a found set of records (or a current record) on the specified layout. Any layout based on a table occurrence with the same data source table as that specified for "Table" can be used to display the resulting found set of records. Thus, when you specify "Things 2" as the "table", the relationship to Things 2 determines what records appear in your found set. Presumably "Things" and "Things 2" are two table occurrences with the same data source table and thus this works to produce the specified found set. (You'll get an error message if the layout's table occurrence is based on a different data source table.)

                  BUT

                  Once GTRR executes and pulls up your found set on the "Things" based layout, your context is now "Things", not "Things 2". If you refer to a field from Things, you are referring to data in the current record in this layout's found set. If you refer to "Things 2", you are referring to data from a record should be related to the current record on your layout. This may be data from a completely different record or it may be a relationship (or there is no such relationship) that does not match to any record and then no value is assigned to your variable.

                  Thus, your set variable step should refer to Things and not Things 2 if you are going to copy data from the current record into your variable.

                  For more on table occurrences, how they work and how to use them, see: Tutorial: What are Table Occurrences?

                  • 6. Re: SetVariable works with GoToPortalRow but not for GTRR?!
                    EmelieLeht

                    Any layout based on a table occurrence with the same data source table as that specified for "Table" can be used to display the resulting found set of records. Thus, when you specify "Things 2" as the "table", the relationship to Things 2 determines what records appear in your found set. Presumably "Things" and "Things 2" are two table occurrences with the same data source table and thus this works to produce the specified found set.

                    Yes, this is exactly the case! Very nice to have it confirmed that it works that way.  Also, it really should be in the GTRR details. Seems like there is a lot missing in the documentation on it. I read one of your great posts on the topic.

                    Once GTRR executes and pulls up your found set on the "Things" based layout, your context is now "Things", not "Things 2". If you refer to a field from Things, you are referring to data in the current record in this layout's found set. If you refer to "Things 2", you are referring to data from a record should be related to the current record on your layout.

                    This is also great. I found out by trial and error that this must be the way to do it but to me it seemed strange that the context (layout) somehow comes higher in priority than the data (table). I am not sure if you actually wrote about this in the long GTRR post as well but it is not until this commen i really grasepd it. Thank you very much!

                    • 7. Re: SetVariable works with GoToPortalRow but not for GTRR?!
                      philmodjunk

                      Layouts cannot change their table occurrence context so once GTRR delivers you to the new layout, that layout's context is what has to take over at that point.