AnsweredAssumed Answered

Script to duplicate record and multiple related records

Question asked by MichaelGarner on Oct 2, 2013
Latest reply on Oct 3, 2013 by philmodjunk

Summary

Script to duplicate record and multiple related records

Product

FileMaker Pro

Version

12

Operating system version

MAC OS 10.8.5

Description of the issue

I wrote the following script to duplicate an existing record along with its related sub-records:

Go to Related Record [Show only related records; Match found set: "Labor Hours"; Using layout: "Related Labor Hours" (Labor Hours)]
Go to Related Record [Show only related records; Match found set: "Material Items"' Using layout: "Related Material Items" (Material Items)]
Go to Layout ["Project Input & Detail" (Projects)]
Duplicate Record/Request
Set Variable [$ID; Value: Projects::_Project Ref #1]
Go to Layout ["Related Labor Hours" (Labor Hours)]
Loop
     Exit Loop If [Get(FoundCount) = 0]
     Go to Record/Request/Page [First]
     Duplicate Record/Request
     Set Field [Labor Hours::_Project Ref #;$ID]
     Omit Record
     Go to Record/Request/Page [First]
     Omit Record
End Loop
**Did same loop language for Related Material Items**
Go to Layout ["Project Copy Layout" (Project)]
Go to Field [Projects::Customer Ref #]
Show Custom Dialog ["New Customer ID"; "Enter New Customer Reference #"]

Script runs fine when I have related records in the Labor Hours and Material Items table, but if there are no records associated with the Project in the sub-tables, then the script copies all of my Labor Hour or Material Items to the duplicate Project.

Any suggestions would be greatly appreciated.

Outcomes