El_Pablo Posted January 27, 2010 Posted January 27, 2010 (edited) Hi, Is there an efficient way to duplicate a record and its children? (Yes, I need to duplicate some of the children) The algorithm I'm thinking of is : duplicate the parent record Get its primary key Go to original record Traverse all children // TEDIOUS PART!! Duplicate each child change foreign key to new parent The long part is to traverse allll children tables, when there are like few levels of them, it's so long to script. I just want to know if there is a generic way to do it? Edited January 27, 2010 by Guest
Søren Dyhr Posted January 27, 2010 Posted January 27, 2010 (edited) Well your choice of platform prevent you from doing this: http://tokerud.typepad.com/filemaker/2006/06/new_record_with.html Is it? --sd main.zip Edited January 27, 2010 by Guest
El_Pablo Posted January 27, 2010 Author Posted January 27, 2010 Hmmm... I don't think that changing all the desktop to Mac is a wise choice. : Do you know if there is a vbscript equivalent?
El_Pablo Posted January 27, 2010 Author Posted January 27, 2010 I don't want to do a 100+ line script! :tears:
Søren Dyhr Posted January 27, 2010 Posted January 27, 2010 No 21 lines would do, and this is without any tightning up at all. See the attachment to my previous now modified post. --sd
El_Pablo Posted January 27, 2010 Author Posted January 27, 2010 Hmmm... interesting. But how about children of children table? Do you have to create a layout and a portal for each one of the table occurrences? In my case, the report has at least 20 children tables going through 4 levels... I guess tweaking around using portals and a recursive script I can get to something. Although I see a problem with the GTRR since it's not "customizable".
El_Pablo Posted January 27, 2010 Author Posted January 27, 2010 I like the "get (scriptparameter)" in the fk_main! But can there be a problem using this method? Like creating a child record from another script?
Søren Dyhr Posted January 27, 2010 Posted January 27, 2010 Yes there can obviously, but you can then make the autoenter conditionally via Case(GetScriptName( = "someting" http://fmhelp.filemaker.com/fmphelp_10/en/html/func_ref2.32.63.html --sd
El_Pablo Posted January 28, 2010 Author Posted January 28, 2010 After searching here and there, I think I will have to create a megascript since the record type I want to duplicate has 31 dependent children under 4 levels.. If there was a generic GTRR (sort of GTRR by name) this would simplify my script greatly.
El_Pablo Posted January 28, 2010 Author Posted January 28, 2010 Wouldn't it be nice if this algorithm could translate to FM : script DuplicateRecordTree (parentID as string) begin Duplicate Record pk = newRecord.pk if (parentID <> "") Set newRecord.fk = parentID end if omit record if (currentTable.hasChildTables) foreach (childT in currentTable.childTables) if (childT.records.related.count > 0) foreach (r in childT.records.related) Goto Related Record® DuplicateRecordTree (pk) next end if next end if end script
Søren Dyhr Posted January 28, 2010 Posted January 28, 2010 If there was a generic GTRR (sort of GTRR by name) this would simplify my script greatly. You can borrow an idea or two from this approach: http://web.mac.com/zueiv/iWeb/FileMaker/Script%20Killing%20Techniques/AFA363C6-2D85-4C6D-82E2-273F3722A69E.html --sd
El_Pablo Posted January 28, 2010 Author Posted January 28, 2010 Hey thanks! That's pretty interesting. Thanks also for the web didn't know this one.
Recommended Posts
This topic is 5413 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now