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?

Powered by WPeMatico