Need a snippet to clone a record, its children and its children's children...

I am creating a “template” function where the user will create a parent record, create children of that parent, then create children of those children. That will serve as a template. That part I have down. The part I need is for the user to click a button that will clone the parent, the children, and the grandchildren. I wrestled with declarative options for this, but I hit a wall. One of the complexities is that the record need to be cloned, then the children need to be cloned and associated with the cloned record, not the original. Then the grandchildren need to be cloned and associated with the newly cloned children, not the original children. Has anyone endevored to do such a thing?

Wooot! Woooot!!! This one functionality is one of the main reasons I started using Skuid. It’s by far one of the more unknown super cool functionalities.

You can setup models to always clone. In the same way a page detail is setup with it’s children and even grandchildren, you can copy a detail page for record cloning purposes by simply setting the desired models to clone - “Always”. The entire structure of the original is cloned to as many records as the save operation can handle, which is hundreds or even thousands of records.

Simply awesome functionality.

Help me master of the clone! How is this done. I have been trying to do it from a row action on a table. Are you saying that I need to set up a detail page to accomplish this? How does this work? -Say I have an account named ABC company - I have 3 contacts linked to the ABC Company - I have 4 tasks linked to each of the 3 contacts (12 In all). How do I clone all of these with a button push and get them all connected correctly? I was using clone always based on your previous help on this topic earlier this year (I gave up and am just now getting back around to it months later). I was doing a set of actions from a row action to clone one level at a time… I couldn’t get them linked properly, though. Any help would be appreciated.

It’s all in the query setup. The conditions have to use the results of their parents, just like a detail page. The query action has to have all the models selected.

I can jump onto a skype call later if you like. pat.vachon.77

You are the best, Pat… I was swamped today, but I will reaclimate myself to where I left off on this a couple months ago, then take you up on your offer. Thanks!

Know the feeling. I’ve been swamped as well. Lemeno

Edited for more clarity:
This is still on my to do list. It occurs to me re-reading your comments that I may be making this harder than it is (which may be extremely simple).

Say I wanted to create a detail page of an account that had a table in it of all of that account’s contact children and a second table that would display all of the tasks related to all of the contacts that are children of the Account.

That page would have three models. The account model would be limited to one specific account record. The contact model would be limited to those with the parent of the specific account. The tasks model would be limited to those tasks related to the contacts.

Let’s say I get this page up and running as expected. There is one Account, there are five contacts, and there are twelve tasks displayed on the page. A total of 18 records in all are returned by the queries.

Are you saying that if I:

1) Add a save button to the page that saves all three models

2) I go into the model settings of each of the three models and change them to clone always .

3) I load the page

4) I click the save button that saves all three models

Then the following will occur:

1) One new account will be created

2) five new contacts will be created that are associated with the newly created account

3) 12 new tasks will be created that are associated with the coresponding newly created contacts?

That is what I’m saying. Spot on. All 3 models will create new cloned versions of the records on page load. All that’s left is to click Save.

Mind blown. I spent like 4 hours trying to build and troubleshoot a crazy action sequence to accomplish this. Got it to work for children but never for grandchildren. I’ll give this a try. Thanks!

Just be sure to include all models in one save action and all should work.

Will do. Thanks.