Our Preferred 5 Star Hosting Provider - Award Winning FileMaker Pro Hosting
Results 1 to 4 of 4

Thread: Nested Loop

  1. #1
    Forum Member
    Join Date
    Apr 2017
    Posts
    1
    Location
    Italy
    FileMaker Pro Software
    FileMaker 14 Advanced
    OS
    Mac
    Skill Level
    Intermediate
    Last Post
    04-08-2017
    Local Date
    10-20-2017
    Local Time
    04:28 AM
    Last Active
    04-08-2017

    Nested Loop

    Hi everyone
    I’ve got a big problem.
    I’ve made a database for dietitian, composed by
    - table: Patients
    - Table: Diets
    - Table: Days
    - Table: Meals
    - Table: join_meal_food
    - Table: foods

    Each patients has got multiple diets
    each diet has got multiple days
    each day has got multiple meals
    each meal has got multiple foods.

    So, what I’m trying to do is duplicate a diet by script, so I’d obtain a new diet with the same characteristics of the original one.

    I’ll try to report here the script simplifying:

    Set variable $OldDietID (the ID of the diet I want to duplicate)
    duplicate the diet record
    set variable $NewDietID

    go to table: Days (it has more than one day)
    find the OldDietIDFK
    go to the first record
    set variable $OldDayID

    loop
    duplicate record
    set variable $NewDayID
    set field “dietIDFK”: $NewDietID
    omit record
    go to the first record
    omit record

    go to table: Meals (it has more than one food)
    find the OldDietIDFK
    find the OldDayIDFK
    go to the first record
    set variable $OldMealID

    loop
    duplicate record
    set variable $NewMealID
    set field “dietIDFK”: $NewDietID
    set field “dayIDFK”: $NewdayID
    omit record
    go to the first record
    omit record

    go to table: Join_meal_food
    find the OldDietIDFK
    find the OldDayIDFK
    find the OldMaelIDFK
    go to the first record

    loop
    duplicate record
    set field “dietIDFK”: $NewDietID
    set field “dayIDFK”: $NewdayID
    set field “mealIDFK”: $NewMealID
    omit record
    go to the first record
    omit record

    exit loop if [Get (FoundCount)=0]
    end loop

    exit loop if [Get (FoundCount)=0]
    end loop

    exit loop if [Get (FoundCount)=0]
    end loop


    The problem is that when it duplicates the first meal, and only the first, and exit the loop.

    Does anybody help me?

  2. #2
    Senior Moderator - FMT Preferred Developer Consultant - Netherlands, Europe, Asia, USA Maarten Witberg's Avatar
    Join Date
    Mar 2004
    Posts
    6,135
    Location
    netherlands
    FileMaker Pro Software
    version 11, 12, 13, 14, 15
    OS
    Windows & Mac
    Skill Level
    Developer
    Last Post
    06-29-2017
    Local Date
    10-20-2017
    Local Time
    12:28 PM
    Last Active
    07-16-2017
    It looks like you are not returning to the previous layout after a loop exits.


    Code:
    loop
        duplicate record
        set variable $NewDayID
        set field “dietIDFK”: $NewDietID
        omit record
        go to the first record
        omit record
    
        go to table: Meals (it has more than one food)
        find the OldDietIDFK
        find the OldDayIDFK
        go to the first record
        set variable $OldMealID
    
        loop
            duplicate record
            set variable $NewMealID
            set field “dietIDFK”: $NewDietID
            set field “dayIDFK”: $NewdayID
            omit record
            go to the first record
            omit record
    
            go to table: Join_meal_food
            find the OldDietIDFK
            find the OldDayIDFK
            find the OldMaelIDFK
            go to the first record
    
            loop
                duplicate record
                set field “dietIDFK”: $NewDietID
                set field “dayIDFK”: $NewdayID
                set field “mealIDFK”: $NewMealID
                omit record
                go to the first record
                omit record
                exit loop if [Get (FoundCount)=0]
            end loop
    
            #go back
            go to layout [ meals ]
    
            exit loop if [Get (FoundCount)=0]
        end loop
    
        #go back
        go to layout [ days ]
    
        exit loop if [Get (FoundCount)=0]
    end loop
    Stick to what you don't know.

    http://www.maartenwitberg.nl

    Filemaker 15 Certified Developer

    -------

  3. #3
    Forum Member
    Join Date
    Dec 2014
    Posts
    7
    Location
    Canada
    FileMaker Pro Software
    14 Advanced
    OS
    Windows
    Skill Level
    Pro
    Last Post
    05-02-2017
    Local Date
    10-20-2017
    Local Time
    03:28 AM
    Last Active
    10-16-2017
    at the end of each loop you must have the script step "Go to records/Request/page[Next]" I think the best place is before each "Exit Loop If" script step.
    Siroos Jafary



    Intelligence Avenue inc.

    Website: www.iavenue.ca

    Email: info@iavenue.ca

  4. #4
    Senior Moderator - FMT Preferred Developer Consultant - Netherlands, Europe, Asia, USA Maarten Witberg's Avatar
    Join Date
    Mar 2004
    Posts
    6,135
    Location
    netherlands
    FileMaker Pro Software
    version 11, 12, 13, 14, 15
    OS
    Windows & Mac
    Skill Level
    Developer
    Last Post
    06-29-2017
    Local Date
    10-20-2017
    Local Time
    12:28 PM
    Last Active
    07-16-2017
    at the end of each loop you must have the script step "Go to records/Request/page[Next]"
    Not in this case where the found set is reduced by the Omit records script step. The script terminates too soon because it doesn't return to the previous layout after each sub loop.
    Stick to what you don't know.

    http://www.maartenwitberg.nl

    Filemaker 15 Certified Developer

    -------

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. exit inner loop not working and exits main loop
    By alienandra in forum FileMaker 13 - All Versions
    Replies: 7
    Last Post: 11-03-2015, 07:24 PM
  2. Nested Loop
    By barry685 in forum ScriptMaker and Scripting
    Replies: 6
    Last Post: 10-26-2013, 05:47 PM
  3. Nested loop
    By rishikshetry in forum ScriptMaker and Scripting
    Replies: 2
    Last Post: 01-28-2013, 10:48 AM
  4. nested if
    By parker in forum FileMaker Pro Versions 5 & 6
    Replies: 8
    Last Post: 12-16-2004, 01:37 AM
  5. Loop doesn't loop when "new record/request"
    By qling in forum ScriptMaker and Scripting
    Replies: 1
    Last Post: 02-17-2004, 04:30 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Welcome to the Original FileMaker Forum
With designated forums for almost every FileMaker topic...FileMaker Today is a FREE to join community where you can boost your FileMaker expertise, build better apps & solutions and interact with over 42,000+ FileMaker Developers from all over the world. If you're building FileMaker solutions, this is the place for you.
Follow FMT
We Are FMT
FMT is home of The World's leading FileMaker News Site, Worldwide Developer Directory, FileMaker Connect Community and so much more.