14 Replies Latest reply on Jul 1, 2013 10:51 AM by AnthonySenerchia

    How do I make an array in Filemaker Pro 11

    carolyn

      Title

      How do I make an array in Filemaker Pro 11

      Post

      I'm new to Filemaker Pro 11 scripting.  I have been scripting AppleScript for a number of years. I was hoping someone could tell me how to create a list variable (array) using Filemaker Pro's scripting lanuage.  Or if someone could please point me to where I could get more information.

       

      Thanks for any help.

        • 1. Re: How do I make an array in Filemaker Pro 11
          philmodjunk

          You have more than one option here depending on what you want to do.

           

          1. You could use a repeating field--though this is rarely the best option.
          2. You can use a table of related records--good choice if you need to store your list of data for future use
          3. You can use a value list in either a variable or a field. This is a list of values separated by returns and GetValue ( Listfieldorvariable ; itemnumber) can be used to refer to a specific item in the list.
          4. You can use a repeating variable such as $Avariable, Set Variable enables you to specify a specific repetition and you can use $AVariable[2] in an expression to refer to the second repetition much like you would with array notation in many computer languages.
          • 2. Re: How do I make an array in Filemaker Pro 11
            carolyn

            Thanks so much.  Sorry I haven't thanked you sooner.  I got a bit sidetracked.  I think options 3 and 4 would most suit my needs.  I haven't thought of using a related table for this purpose.  hum I'll have to give that more thought.

             

            Thanks again Phil

            • 3. Re: How do I make an array in Filemaker Pro 11
              carolyn

              Hi PhilModjunk or anyone else who woudl like to help,

              I have been working with methods that you have listed above.  It probably is the best option, but I haven't quite worked out how I would use 4 in the workflow I need. I have been learning to use item 3.  But I have not figured out how to get the count.

              In my applescript programming for other solutions, I use arrays and logically linked arrays quite a bit.  In my other programming, I usually don't know the count of the values in the array. My code usually looks something like this:

              set arrayOfItems to every item whose some property = some value

              repeat with i from 1 to count of arrayOfItems

              set curItem to item i of arrayOfItems

              --\\ do something based on curItem

              end repeat

              My current application for arrays is getting the field names on a layout and cycling through those fields picking up their values thus creating a logically linked array of field names and field values.

              So far I have defined a variable with values separated by returns by setting a variable to FieldNames(). I set an iteration variable and show each field name by using GetValue($NamesVariable; $iterationvariable). Since I don't know how to get the count I have been using exist loop if GetValue($NamesVariable; $iterationvariable) = "".  While in my small test environment this seems to work, I think that there must be a more standard method by determining the total count and exiting it if it is reasched.  How would I do that?

              Also, do you have examples of creating repeating variables when you don't know the values as in the example above?

              Thanks so much.

              • 4. Re: How do I make an array in Filemaker Pro 11
                philmodjunk

                You can use the ValueCount function to count the number of values in a list of values.

                Here's an example script that may serve:

                Set Variable [ $FieldList; Value:FieldNames ( Get ( FileName ) ; Get ( LayoutName ) ) ]
                Set Variable [ $I; Value:1 ]
                Set Variable [ $J; Value:1 ]

                Loop 
                  Set Variable [ $FieldValue; Value:GetField ( Get ( LayoutTableName ) & "::" & GetValue ( $FieldList ; $I ) ) ]  
                  If [ not IsEmpty ( $FieldValue ) /* field had a value */ ]  
                    Set Variable [ $List[$J]; Value:$FieldValue ]  
                    Set Variable [ $J; Value:$J + 1 ]  
                  End If  
                  Set Variable [ $I; Value:$I + 1 ]  
                  Exit Loop If [ $I > ValueCount ( $FieldList ) ]  
                End Loop  

                Set Variable [ $I; Value:1 ]  
                Loop  
                  Show Custom Dialog [ Message: "$List[" & $I & "] = " & $List[$I]; Buttons: “OK” ]  
                  Set Variable [ $I; Value:$I + 1 ]  
                  Exit Loop If [ $I > ( $J -1 ) ]  
                End Loop

                • 5. Re: How do I make an array in Filemaker Pro 11
                  etripoli

                  I'd like to say one thing up front - FileMaker is a database application that includes scripting language, not the other way around.  Because of that, there is very limited support for complex programming techniques, like arrays, because the array functionality is actually contained in the tables, records, fields, and the ways to manipulate them.  And really, arrays are just an extremely simplified version of a database.

                  And while you could, and sometimes have to, create custom functions for dealing with multi-value lists, it's usually the exception, and it also usually turns out to have a simplier solution using tables & relationships instead.  So, maybe if you give us an idea of what you are trying to accomplish, we can offer alternatives.

                  • 6. Re: How do I make an array in Filemaker Pro 11
                    carolyn

                    Once again thanks Phil.

                    Also, thanks etripoli, for the offer to show alternative solutions.  I'll remember that in the future.  I am supprised though about Filemaker's limited support for arrays.  Even in a database tool, having support for arrays is a tremendous asset.  I had the opportunity to work with 4D, a RAD database tool, which has strong support for arrays. You would be amazed at the power and flexibility arrays provide in comparing information even within a database environment.  That being said I'll keep searching for FM Pro way.

                    • 7. Re: How do I make an array in Filemaker Pro 11
                      carolyn

                      Does FM Pro have an easy or automatic way to create an audit trail of changes?

                      • 8. Re: How do I make an array in Filemaker Pro 11
                        etripoli

                        I've not had the opportunity to use 4D, but I've used most other database systems.  One could say that FileMaker is limited in comparision to the others, but at the same time, the limitations lead to easier-to-create, -use, and -maintain, databases.  While there probably is some way of creating and maintaining arrays in FileMaker, the 'layout' is basis of FileMaker, with the associated structure to support it, so use that to your advantage.

                        As for the audit trail, that's something most people desire in FileMaker at one time or another, and with version 10 and beyond, is possible with script triggers.

                        • 9. Re: How do I make an array in Filemaker Pro 11
                          carolyn

                          Your comment is much appreciated. I understand your point. Hopefully I can use all technology to it's best advantage.

                          • 10. Re: How do I make an array in Filemaker Pro 11
                            developerS

                            Hi,

                            I am trying to create an array in filemaker that will hold the contents of fields in a specific record. Here's what Im trying to do:

                            I have two different tables: one is "answers" and the other is "grades". A student will answer a list of questions specified on the "answers" layout/form. They will then hit "next". Once they do I want to dun a script that will compare their answers to a marking scheme and display the grade.

                            The marking scheme is a record/instance of the "answers" table with student ID 11111 and Student name: marking scheme.

                            I want to temporarily hold the correct answers in an array and then loop through the form answered by the student and compare each field to the corresponding field in the marking scheme.

                            I created a variable $Counter starts at zero and $Scheme[15] (I have 15 questions). i then tried to set $Scheme[$Counter] = Get(ActiveFieldContents0, this is giving me an error. It says I cant use `[]`.... What should I do

                            Any reply is appreciated! Thanks

                            • 11. Re: How do I make an array in Filemaker Pro 11
                              mcgrailm

                              Does this

                                Set Variable [ $List[$J]; Value:$FieldValue ] 

                              only  work in filemaker 11  ? I have ten and can't seem to get this to work. I  keep getting an error saying I have invalid charaters

                              • 12. Re: How do I make an array in Filemaker Pro 11
                                rjlevesque

                                try () for calculation container within calculation and "" for contextual contents

                                • 13. Re: How do I make an array in Filemaker Pro 11
                                  LaurenceHarrould

                                       Hi guys

                                       I have a similar issue. When I try to assign a value to variable using the "Set Variable [ $List[$J]; Value:$FieldValue ] " format I get an error telling me I'm using invalid characters when I try to designate the $List[$J] component.

                                       The objective: I have a group of an unknown number of people who have to be grouped into teams of 3. This has to be done 3 times a year and no group can have the same people in the 3 periods. My approach is to have a list of participants and using different algorithms for each period have a different way of selecting the team members. The challenge in this part is to keep track of which people have alredy been allocated because if there are people at the end who haven't been placed in a team I need to do that manually - there will either be 1 or 2 left over. The question is how do I know who's been unallocated?

                                       My approach is to have an array containing the list of personIDs. As each person is allocated I'd remove their ID from the array and then see who's left at the end. I know I can do this with a temporary table but it's tedious (and time consuming) having to go between layouts and so I was looking for a way to avoid that.

                                       I'm using FMP 12

                                       Thanks & regards

                                       Laurence

                                  • 14. Re: How do I make an array in Filemaker Pro 11
                                    AnthonySenerchia

                                         I know this is an old post, but the error that pops up when trying to enter $List[$J]  in the SetVariable dialogue "Name:" field is because $J should be entered in the "Repetition:" field, not directly with the name.

                                         So, this would give:

                                          

                                         Name: $List

                                         Value: $FieldValue

                                         Repetition: $J

                                          

                                         for that line of code.

                                         Hope that helps.