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?
Tagged:
1
Categories
- 7.9K Questions
- 926 Ideas
- 220 Discussion Categories
- 178 General
- 9 Community Feedback
- 3 Community Info
- 18 Knowledge Base
Comments
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.
I can jump onto a skype call later if you like. pat.vachon.77
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?