3 Replies Latest reply on Sep 10, 2012 11:46 AM by philmodjunk

    Loop help

    ultranix

      Title

      Loop help

      Post

      I want help on this thing. I believe loop is the best solution?

      1. User clicks on the button "Create new activity records"

      2. Custom dialog is shown and the user inserts the desired number of new activity records (let's say, 23) to be created in the input field

      3. Clicks OK.

      After that, script should create as many records as it was entered by the user in the input field.

      For the creation of each record, such script steps are necessary:

      New Record/Request

      Set Field id_activity $ID

      -----------------------------

      Activity description fields are left blank, because they vary greatly and user will edit those fields manually later.

      So how again I could create the desired number (it can be 23, 28, 36, etc.) of new records?

        • 1. Re: Loop help
          philmodjunk

          Use a global field for you custom dialog's input field such as Globals::gNumRecs

          then your loop can be:

          Go To Layout [//Specify layout based on your table of activity records here]
          Loop
            Set Variable [$K ; value: $K + 1 ]
            Exit Loop If [$K > Globals::gNumRecs]
            New Record/Request
            Set Field [ActivityTable::id_activity ; $ID]
          End Loop

          • 2. Re: Loop help
            ultranix

                 I'd need to take it to the next level. Let's say I've got the list of those descriptions in .txt. As to copy/paste them all would be a painful, time-consuming and least attractive use of my time, I thought of doing it this way:

                 In addition to what was described already:

                 1. User clicks on the button "Create new activity records"

                 2. Custom dialog is shown and the user inserts the desired number of new activity records (let's say, 23) to be created in the input field

                 I would add one more step - Add global field, in which I could copy/paste .txt file contents and then click OK.

                 After I click OK, not only it would create 23 records using loop script and set ID_activity, but also it would parse text of the global field, and fill in "description" field. I believe it would be somewhat similar as you wrote here: http://forums.filemaker.com/posts/9bd322ed0c

                 There just would not be two lines, that don't need to be parsed, every line is necessary and 1st line of that text corresponds with 1st activity record, 2nd line with 2nd and so on.

                 So basically two things here: ability to set custom number of records and ability to parse text and set fields with results.

                 Thanks.

            • 3. Re: Loop help
              philmodjunk

                   If there is one line of text in the global field for each record to be created, you don't have to ask the user to enter a number, you can just loop through the lines of text in the global field. Instead of copy/paste, you also have the option to import the text into a table in your database. That could create the records and enter the text for you without a need for any action except that of importing the record from the .txt file.