3 Replies Latest reply on Aug 3, 2015 8:52 AM by DylanMajka

    Help with Variable Repetitions

    DylanMajka

      Title

      Help with Variable Repetitions

      Post

      Hi guys,

      What I'm trying to do is set up a script that will allow a user to temporarily store a group of found records uniquely named by a particular field (in this case Order ID) and then later recall those found records without having to do the search all over again.

      The way in which I am going about this is by trying to set up a script that will store the Order ID for each record in a repetition of a global variable.  So far this is what my script looks like:

      Loop

      Set Variable[$$Count; Value:Get(RecordNumber)]

      Set Variable[$$ID[$$Count] ; Value:Orders::Order ID]

      Go to Record/Request/Page [Next; Exit after last]

      End Loop

      I'm not sure if I am misunderstanding how variable repetitions work, but I'm under the impression that they should be able to be recalled similarly to an array in any other programming language.  However, I'm running into an issue getting FileMaker to recall them; it almost seems as though it's only storing one ID in the variable.

      Any idea what I might be doing wrong?

        • 1. Re: Help with Variable Repetitions
          philmodjunk

          If your script starts on the first record in your found set, this approach should work though you can do this without having to loop through the records if you are using v13 or newer.

          And while it should not keep this from working, I see no reason to make $$count a global variable. A script variable, $Count, should work just fine.

          You are putting $$Count in the repetition box in the set variable dialog?

          What makes you think that you are only getting one ID entered into this variable?

          The nonlooping method is to define a "list of" summary field to list your Order ID field. Then you can simply set your variable to the value of this summary field.

          This produces a return separated list rather than an array, but that, via a relationship, can actually be a simpler way to use such a set of ID's to produce a found set than by using a repeating variable.

          • 2. Re: Help with Variable Repetitions
            DylanMajka

            Unfortunately I'm using v12...

            The reason I think I'm getting only one ID entered is that when I go to access the ID stored in the variable, I can only get it to produce the ID stored in the first repetition.  I might be going about this second part wrong... but to reproduce the found set I built another script that looks something like this:

            Set Variable [$Find; Value:GetRepetition ($$PO; $$Count)]

            Perform Find (Where Order ID == $Find)

            Loop

            Set Variable [$$Count; Value: $$Count - 1]

            Set Variable [$Find; Value:GetRepetition ($$PO; $$Count)]

            Extend Found Set (Where Order ID == $Find)

            Exit Loop If [$$Count = 1]

             

            I might be using the wrong function to access the repetitions... But this is where I'm running into issues.  I tried testing it by taking out the count variable in the GetRepetition function and instead using a constant, but it won't produce any of the other repetitions aside from the first one.  The reason I'm using Count as a global variable is so that when I run the second script, it has access to the number of ID's stored in the variable.  Am I thinking about variable repetitions the right way?  The repetition is similar to the index in an array right?

            • 3. Re: Help with Variable Repetitions
              DylanMajka

              Hi PhilModJunk,

              I was wondering if you had any other information on resolving this issue, I've been toying around with it but still can't find a solution.