1 2 Previous Next 18 Replies Latest reply on Jan 19, 2017 6:07 PM by jmproulx

    How to Locate a Last Portal Row after a Change in Focus ?

    jmproulx

      I have to change focus ( to get data from a related table ) in order to populate the fields of the last row of a portal. I use a script triggered by OnRecordCommit on the Name field of the portal row. The parameter passed to the script is the value of the Name field. The script performs a find in the related table and locate the record with the Name value. I then get the data pertaining to the record found.

       

      Before changing focus I saved the portal row number in a variable. When I come back to the original portal, I try to set the fields with the data I obtained from  the related table. I go to the row using the saved row number. Then I set fields with the data.

       

      Very simple logic. But I never succeed to populate the right row, the one I quitted. I always get 2 rows, the one I would like to update on which only the Name field is updated and another one that contains all the updated fields I want.

       

      I believe that changing layout has committed the partially updated row and coming back has created a new fully updated row.

       

      I have tried many instances of Go to Portal Row (Last, Previous, By Calculation) without being able to catch the right one.

       

      There is something I am missing.

        • 1. Re: How to Locate a Last Portal Row after a Change in Focus ?
          philmodjunk

          You might be able to use a relationship to access the data without changing focus. You might also avoid creating the portal record until after you have searched the related table--you might enter all your data into global fields, for example and not create the portal record until all data is ready to go in the globals. You could also use the MagicKey method to create the related record and not interact with a portal row at all to create a record.

           

          But what you are trying to do should work if you pay attention to detail. You are correct that the layout change commits records so the last record now becomes the blank "add row" not the record that you have started to populate with data. You could use go to portal row [last] followed by Go To Portal Row previous or you can set a variable to get (activePortalRowNumber) before you change focus so that you can use the calculation option with the variable to return to the original portal row but a sort order on the portal or in the relationship could keep that from working. And if you have more than one portal on your layout, you have to put the focus on the correct portal before going to a portal row.

           

          So I recommend using the MagicKey method instead of interacting with a portal row. It's less brittle.

          1 of 1 people found this helpful
          • 2. Re: How to Locate a Last Portal Row after a Change in Focus ?
            jmproulx

            Where can I get a description of the MagicKey method ?

            • 4. Re: How to Locate a Last Portal Row after a Change in Focus ?
              jmproulx

              Before asking my question on this community forum I have tried what philmodjunk recommended here :

               

              "You could use go to portal row [last] followed by Go To Portal Row previous or you can set a variable to get (activePortalRowNumber) before you change focus so that you can use the calculation option with the variable to return to the original portal row but a sort order on the portal or in the relationship could keep that from working. And if you have more than one portal on your layout, you have to put the focus on the correct portal before going to a portal row."

               

              The problem occurs only when the Name field is using a specific value list. I have created 3 TOs of the related table. It works fine when the value list of the Name field is based on the 2 TOs specifically created to use a conditional value list. The problem occurs only when I use the value list that is not conditional.

               

              I don't understand the impact of not using a conditional value list although I have created 2 of them with the associated TO relationship.

              • 5. Re: How to Locate a Last Portal Row after a Change in Focus ?
                philmodjunk

                Your last post is very puzzling. We need to see your script and a description of the layout design of your portal. The presence or absence of a value list--conditional or otherwise should have no impact on a script's ability to put the focus on a particular portal row or even a specific field within that portal row.

                 

                But this type of processing is very vulnerable to a number of layout issues--such as your script tripping script triggers that then perform scripts that in turn interfere with the results that you wanted from the original script. It's one of the reasons why I avoid using a portal to add/edit related records whenever possible.

                 

                I suggest using FileMaker Advanced to run your script with the debugger enabled.

                1 of 1 people found this helpful
                • 6. Re: How to Locate a Last Portal Row after a Change in Focus ?
                  jmproulx

                  I am using FileMaker Advanced 15. I did a lot of testing (surely not enough) with the Script Debugger and the Data Viewer as well as the portal opened in table view in a second window. I can see the behavior step by step.

                   

                  My application is all (layouts, scripts, value lists and content) in French. I could show you screen captures but it may be difficult for you to understand.

                  • 7. Re: How to Locate a Last Portal Row after a Change in Focus ?
                    philmodjunk

                    You should be able to see error codes and see focus changes while stepping through the script using the debugger.

                     

                    What do you see when you do that?

                     

                    Do you see any error codes?

                     

                    How does the focus change when you step through the script?

                    1 of 1 people found this helpful
                    • 8. Re: How to Locate a Last Portal Row after a Change in Focus ?
                      BruceRobertson
                      My application is all (layouts, scripts, value lists and content) in French. I could show you screen captures but it may be difficult for you to understand.

                      There are people here who understand French. Though not me.

                      It might be better instead if you create a simplified example file that illustrates what you are trying to do.

                       

                      Also, your terms are still quite vague and that makes it difficult.

                      Name field. Conditional value list. What is this all about?

                      I'm going to try create a simple file that illustrates part of what I think Phil is describing.

                      1 of 1 people found this helpful
                      • 9. Re: How to Locate a Last Portal Row after a Change in Focus ?
                        jmproulx

                        I don't see any error code. I see the creation of 2 records. Although only the 2nd one appears in the portal.

                         

                        I found MY bug !

                         

                        The portal in which I am creating rows is filtered. The filtering field is an element of the 2 relational value lists for which the triggered script works fine. It does not work if I use a 3rd value list (not relational) leaving the filtered field in the committed record (when the script change layout) empty at that time. As a consequence, when the script step goes to the portal (named) and sets fields on the last record, it is not the same record as the one that was created before going to the portal. Hence, 2 records are created.

                         

                        I was the spectator of a behavior that I didn't understand. I believe now that I do.

                         

                        My dialog with you help me "focus" on the right things.

                        • 10. Re: How to Locate a Last Portal Row after a Change in Focus ?
                          jmproulx

                          I believe should have used relational value list instead of conditional value list.

                           

                          Name is the label of the field of the portal row which triggers (OnRecordCommit) the script. I believe i found my but now. I explained it in an answer to philmodjunk.

                          • 11. Re: How to Locate a Last Portal Row after a Change in Focus ?
                            philmodjunk

                            "Conditional Value List" is the more commonly used term. Most Conditional value Lists use a relationship as the way to "filter" a potential list of values down to a smaller set from which to choose a value.

                             

                            For more on Conditional Value Lists, you might check out:

                             

                            Adventures in FileMaking #1--conditional value lists

                             

                            This is a demo file with multiple working examples of conditional value lists with detailed documentation provided on how each was set up and how it works.

                            1 of 1 people found this helpful
                            • 12. Re: How to Locate a Last Portal Row after a Change in Focus ?
                              BruceRobertson

                              "Name is the label of the field"

                               

                              Well, it may work to keep things abstract.

                              But really. It would help understand your workflow if you would be more complete and use real-world terms. What is this workflow all about? Name of what? Maybe there's a way to simplify this whole workflow.

                              As Phil mentioned, portal-nav methods are inherently fragile.

                              1 of 1 people found this helpful
                              • 13. Re: How to Locate a Last Portal Row after a Change in Focus ?
                                jmproulx

                                Sorry about that. But the field in question holds the name of an ingredient to be included in a recipe. Hence, the name of the field is Name. I agree that this is abstract.

                                 

                                I would like very much to be more concrete in discussing with this very helpful community. But since I work in French, I prefer to describe my problem sometimes in abstract terms than show artefacts that the members will not understand. The onus is on me to be more explicit.

                                 

                                My workflow is simple. I have 3 tables : Recipes, Ingredients and Recipe_Ingredients ( a many-to-many join between the 2 )  where I can find my recipes and their included ingredients. Each recipe is composed of 2 kinds of ingredients : basic ingredients and flavoring ingredients.

                                 

                                To compose a recipe I use a Recipe layout based on the Recipes table. I have included 2 portals on this layout. A portal based on the Recipe_Ingredients table that filters only the basic ingredients. The second portal is also based on the Recipe_Ingredients table but filters only the flavoring ingredients. The filtering field of both portals is called Category whose value is selected respectively from 2 value lists : one for the basic ingredients and another for the flavoring ingredients. Each portal row represents an ingredient in a specific recipe.

                                 

                                As I explained in a message to Phil, I knew that a change of layout ( from Recipe to Ingredients on order to collect the properties of a specific ingredient found in the Ingredients table by using its name ) would make my script loose the focus on the last portal row that was created. I was missing that in returning later in the script to the portal, the last row was not the one that was created before the focus change. Hence my problem in locating the right row.

                                 

                                I hope I have been clearer.

                                 

                                The workflow works fine now. Thank you for your help.

                                • 14. Re: How to Locate a Last Portal Row after a Change in Focus ?
                                  beverly

                                  Please post in French if that is beneficial to you!

                                   

                                  Sent from miPhone

                                  1 of 1 people found this helpful
                                  1 2 Previous Next