2 Replies Latest reply on Aug 25, 2012 9:49 AM by philmodjunk

    Script step to get into repeating field

    LeoWeinstein

      Title

      Script step to get into repeating field

      Post

      Is there a script step that will select the next empty repetition of a repeating field?

       

      Thanks in advance,

       

      Leo

        • 1. Re: Script step to get into repeating field
          davidanders

          http://help.filemaker.com/app/answers/detail/a_id/3209/~/scripting-the-placement-of-the-cursor-into-the-first-empty-repetition
          How do you script the placement of the cursor into the first empty repetition?

          Locating the first empty repetition of a repeating field can help when trying to add to a list of items. For instance, you might want to keep a history of modification dates.

          Before entering the script below you will need to create the following field:

          Counter (global number field)

          Go to Field ["Repeating field"]
          Set Field ["Counter", "0"]
          Loop
          Set Field ["Counter", "Counter + 1"]
          Exit Loop If ["IsEmpty(GetRepetition(Repeating Field, Counter))"]
          Go to Next Field
          End Loop

          If you want to paste something into the last repetition then just add a script command at the very end (outside the loop) to Paste from the clipboard or Paste Special.

          In order for the scripts to work you will need to have all the repetitions in the repeating field follow each other in the tab order. If you have not altered the tab order, then this will already be the case.


          • 2. Re: Script step to get into repeating field
            philmodjunk

            Select it to read info from it or to put info into it?

            Putting info into a repetition:

            Set Field has a repetition box where you can refer to a variable or a field to specify the repetition dynamically.

            Reading data from a repetition:

            Expressions that access data in a repetition can use this syntax: TableOccurrenceName::RepeatingFieldName[Repetition]

            or you can go old school and use the GetRepetition function.

            and Get(ActiveRepetitionNumber) will tell you in what repetition the cursor is currently located.

             

            PS. It's often a better design to use a related table of records instead of a repeating field