AnsweredAssumed Answered

Duplicating Multiple Linked Portals

Question asked by AjEGfmTech on Oct 30, 2014
Latest reply on Nov 1, 2014 by AjEGfmTech

Title

Duplicating Multiple Linked Portals

Post

I am referring to an excellent post by PhilModJunk regarding duplicating portal records.
http://forums.filemaker.com/posts/ac6afe2913

This is working great for me and I understand it. What I'm trying to figure out is how to expand the script to apply to multiple linked portals.

I am creating an store visit form. The form has a hierarchy of elements, each with their own table.

Forms >---< Categories >---< Sections >---< Measures >---< Items

The initial layout starts with a Form and a portal to create Categories. I have used the script above to successfully duplicate a Form and its related portal of Categories. But now each Category will have several Sections. Each Section several Measures. Each Measure several Items. Where do I insert the additional duplicate record loop steps? Below is the 'final' script based on the post referenced above.

#Script to duplicate the entire hierarchy of records for a selected Form.

#Script is intended to be started from the 'Forms List' layout. IF started from 'FormCreate' layout, skip the 'Goto Related Record' step.

Go to Related Record [ From table: “FormCreate”; Using layout: “FormCreate” (FormCreate) ]

Freeze Window

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

#Presume that 'DuplicateRecord' will grab a new UUID?

#FORM

Duplicate Record/Request

Set Field [ FormCreate::Title; "New Untitled Form" ]

#Grab the new UUID.

Set Variable [ $FormID; Value:FormCreate::__pk_FormID ]

#After 'DuplicateRecord' the original record is not necessarily in a predictable place. The GotoRecord with $RecordNumber variable compensates for that.

Go to Record/Request/Page [ $RecordNumber ] [ No dialog ]

#Check to make sure there is at least one FormID foreign key in the Category before proceeding.

#CATEGORY

If [ not IsEmpty ( FormCreate_CATEGORY::_fk_FormID ) // Category records from portal to duplicate. ]

#Goto the related portal record in the layout where it resides.

Go to Related Record [ From table: “FormCreate_CATEGORY”; Using layout: “FormCreate_Category” (FormCreate_CATEGORY) ] [ Show only related records ]

Go to Record/Request/Page [ First ]

Loop

#Duplicate related portal record.

Duplicate Record/Request

Set Field [ FormCreate_CATEGORY::_fk_FormID; $FormID ]

#Remove duplicate record.

Omit Record

Go to Record/Request/Page [ First ]

#Remove original portal record that was duplicated.

Omit Record

ExitLoopIf [Get(FoundCount) =0] End Loop

Go to Layout [ original layout ] Go to Record/Request/Page [ Last ]

End If
Go to Layout
[ original layout ] 

I presume that inside the 'Categories' Loop there would need to be a new 'If' group for 'Sections'? I presume it would be right after the 'DuplicateRecord' and 'SetField'? This method would end up with quite a set of nested Loops and If statements. Is this the best/proper way to do something like this?

I am interested in any advice. Thanks!

Outcomes