6 Replies Latest reply on Jan 12, 2011 6:42 PM by HowardRathbun

    How can I make adjustable Merge Field names?



      How can I make adjustable Merge Field names?


      I have a couple of layouts with large quantities of Merge Fields (thank goodness for this capability).  One layout contains 20 Merge Fields arranged in rows and columns.  The script that sets these fields is identical or nearly identical for every field.  For example, if I want to clear the fields, I must write 20 lines of script (eg set variable $$a1, "")  for the first field and $$a2 for the next and so on.  It would be much more effective if I could use $$an for the field names where $$a is common to all fields and n is a number (variable) that changes from 1 to 20.  Then it would be a simple matter to use a For I = 1 to 20 Next script (the equivalent Loop steps) to clear all the fields.  A second such loop could use the same concept to set the fields and since the script for setting the fields is identical or nearly so for each field, a huge amount of code could be eliminated.

      I fooled around with the concept of adding a variable (eg "n") to the field name (eg "$$a" ) but didn't get anywhere.

      Can this be done?

        • 1. Re: How can I make adjustable Merge Field names?

          Hi Howard

          Are you aware that variables have repetitions? This effectively makes a single variable an array. And the repetition selected can be specified with the calculation engine (even using a script variable).

          So I think your solution will work using a loop with i=1 through i=20 specifying the repetition of the variable ($aa) in each pass.

          TS_Oz, FileMaker Inc.

          • 2. Re: How can I make adjustable Merge Field names?

            Wow, fast response.

             No I hadn't paid attention to "repetition"  in the script steps.  So do I use the same name on all 10 merge variables (eg $$aa) on the layout?  And then keep track of which variable in the array I'm setting based on the loop variable?

            And it seems like I can clear all 10 variables with one script step. 

            The possibities are exciting.  Your response was so fast that I haven't played with this yet.

            Thanks,  Howard

            • 3. Re: How can I make adjustable Merge Field names?

              You can write a script like this:

              Set Variable [ $counter; Value:1 ]


                Set Variable [ $$aa[$counter]; Value:Middle ( "abcedfghijklmnopqrstuvwxyz" ; Random * 26 ; 1 ) ]

                Set Variable [ $counter; Value:$counter + 1 ]

                Exit Loop If [ $counter ≥ 10 ]

              End Loop

              See how I am using one variable ($aa) and setting the repetitions with the value of $counter?

              You would need to clear the repetitions with a similar loop.

              TS_Oz, FileMaker Inc.

              • 4. Re: How can I make adjustable Merge Field names?


                I wrote a script using your loop but had problems.  I may have confused things with my first query where I said "merge fields" when I think I should have said "merge variables".  Anyway I can't figure out how to name the merge variables.  I tried using $$aa for 5 identical merge variables but that put identical data in all 5 merge variables.  Then I named them $$aa1, $$aa2, etc and then no data was set in any of them.  I examined the variables with the Inspector and saw the ability to specifiy the repetition range and orientation but those settings could not be made on these merge variables.  I then discovered these settings were appliceable only to fields.  So I examined some fields in one of my tables and discovered that I could specify a repetition for a particular field.  Which means I have to populate my layout with fields (from a table) instead of using the merge variable concept.  I haven't tried that concept yet as it requires a rethink of how I present my data on a layout.

                Please let me know if I am missing something here.

                • 5. Re: How can I make adjustable Merge Field names?

                  Hmmm, yes I was looking at your solution in terms of your stated merge fields rather than merge variables. Unfortunately merge variables do not support the use of repetitions. From the Help:

                  A variable used as a merge variable cannot include the repetition (index) number of a repeating field (as in the syntax $variable[repetition]) or a file path.

                  So at this stage, the only solution may be the use of merge fields. As you note, if you place a field on a layout, you can specify which repetition to display. It may work for you for display purposes.

                  TS_Oz, FileMaker Inc.

                  • 6. Re: How can I make adjustable Merge Field names?

                    After reading about repeating fields in Help and a manual I decided to declare one of the fields in a small table as a repeating field with a storage range of 5.  Then I placed that field on my layout and used the inspector to set the repeat range from 1 to 5 and horizontal orientation. In the edit layout mode, the field shows with 5 locations and with the field name in the 1st one.  All as expected.  I got the impression from Help and the manual that nothing more was required.  Since the data is coming from the table which has 5 records in it, it  sounded like the layout would display the same field from each record in the table. However, the layout only displays the field from the first record.  It didn't seem like I needed to do a Loop for 1 to 5 and I couldn't figure out what to put in it anyway.

                    If this works as I think it might, it will be simple and save a lot of code.