10 Replies Latest reply on Nov 28, 2013 7:10 AM by philmodjunk

    Jumping to another table and performing script there

    NolenUglade

      Title

      Jumping to another table and performing script there

      Post

           I have two related tables via one field.  

           Account
           User

           I have a "User" inquiry button on my Account layout that is using an associated drop-list value.  So far the working part of my script is        Go to Layout ["User" (User)]

           My goal is to jump to from Account to User table, and display sorted & filtered User table list.  

           Why is this so hard for me to program?  I understand the flow but...

        • 1. Re: Jumping to another table and performing script there
          philmodjunk

               A bit more detail could be helpful, but:

               1) since you have a relationship, go to related records may be used to both change layouts and also bring up a found set of all records from the target layout's table that are related to the current record on your initial layout.

               2) A scripted find can be set up where you copy a value to a variable, change to the other layout and then perform a find for all records with the value copied to the variable.

          • 2. Re: Jumping to another table and performing script there
            NolenUglade

                 I can't seem to copy my script here from my MacBook Pro but here's what I got.   

                 If [Account::Account = "System A"]

                      Go to Layout["User" (User)]

                      Set Field [User::QuickFind | iOS;""]

                      Find Matching Records [Replace; Account::Account]

                 End If

                 Sorry.  I'm still a newbie with some programming experience.

                  

                  

            • 3. Re: Jumping to another table and performing script there
              philmodjunk

                   Consider this alternative:

                   If [Not IsEmpty ( User::NeverEmptyFIeld ) ]
                         Go To Related Record [Show only related records; From table: User; Using layout: "User" (User) ]
                   Else
                         Show Custom Dialog ["There are no user records related to this account record"]
                   End If

              • 4. Re: Jumping to another table and performing script there
                NolenUglade

                     Thank you PhilModJunk!

                     Here's what I came up with using your advice

                     Go to Related Record [Show only related records; From table: "User"; Using layout: "User" (User)]

                     Sort Records by Field [Ascending; User::Call Order]

                     Taking baby steps...

                      

                • 5. Re: Jumping to another table and performing script there
                  philmodjunk

                       Ok, but please test for the presence of related records. If there are no related records, your script will execute as though the Go To Related Records step was not in the script at all. Any steps after the GTRR step will execute, but now from the wrong layout--which can, in some cases, lead to disastrous results.

                  • 6. Re: Jumping to another table and performing script there
                    NolenUglade

                         It doesn't do anything if no related records are found.  I need to put in place a dialog box saying "No record". 
                         Not sure if i'm replying correctly but the the two tables have only one field related, Account.  

                          

                    • 7. Re: Jumping to another table and performing script there
                      philmodjunk

                           But you have a sort records step that will still execute if no records are found. You don't have to pop up a custom dialog if you don't want to, but it's a good idea to avoid trying to sort records in the other table if there are no related records. Otherwise, you may get a confusing error message that interrupts your script.

                           Since I didn't know what fields exist in your User table, I identified the field to use within the IsEmpty function by the characteristic it must have in order for the script to function correctly. You can refer to any field in User that is never empty of data. Your match field, User::Account would be a good choice to use here.

                           The other way to check for "no related records" is to use Get ( LastError ) in an if step to check for a non-zero error code immediately after the GTRR step. If an error code other than 0 is returned, there are no related records and thus you are still on the original layout.

                      • 8. Re: Jumping to another table and performing script there
                        NolenUglade

                             Okay, I got the custom dialog in but I don't see the Get ( LastError ) command. 

                              

                              

                        • 9. Re: Jumping to another table and performing script there
                          NolenUglade

                               "2) A scripted find can be set up where you copy a value to a variable, change to the other layout and then perform a find for all records with the value copied to the variable."

                          I'm trying to understand this.  I can't find a working example that uses one or more variables.  I might want to use something like this in the near future.

                               Update:  Found your answer here:  http://forums.filemaker.com/posts/66911846f0?commentId=228159#228159    Thank again.

                          • 10. Re: Jumping to another table and performing script there
                            philmodjunk

                                 The Get function has many different parameters: LastError, ScriptParameter, ActiveFieldContents, and so forth. You can look this function up in help to get the whole list. It is a function that you use in a calculation such as that needed for an If script step. It is not a script step.

                                 In the specify calculation dialog, the Get function is initially listed once as Get ( flag ) and if you select this option to add it to your calculation, you'll hve to type in the parameter flag value for the result that you want. If you first select Get Functions from the View drop down, you'll see all the different get functions listed so that you can select the correct one without having to type in the parameter.