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

edited June 25, 2020 in Questions
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?

Comments

  • Pat VachonPat Vachon 💎💎💎
    edited June 25, 2020
    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.
  • edited June 25, 2020
    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.
  • Pat VachonPat Vachon 💎💎💎
    edited October 25, 2016
    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
  • edited December 7, 2016
    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!
  • Pat VachonPat Vachon 💎💎💎
    edited November 15, 2016
    Know the feeling. I've been swamped as well. Lemeno
  • edited June 25, 2020
    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?
  • Pat VachonPat Vachon 💎💎💎
    edited January 9, 2017
    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.
  • edited January 9, 2017
    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!
  • Pat VachonPat Vachon 💎💎💎
    edited January 9, 2017
    Just be sure to include all models in one save action and all should work.
  • edited January 9, 2017
    Will do. Thanks.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!