Being a relational database - Quick Base often has several layers of data working within a parent/child hierarchy. Projects will have many Tasks, Leads will have many
Activities, Invoices have many Line Items, etc. etc. You might have found yourself in a position to 'copy' a record at some point, by clicking 'More' from a Quick Base form and selecting the copy link. The problem with this is that you only end up copying that record. None of the children copy with it. For example - you would wind up with a copy of your Invoice with no lines.
Enter API_CopyMasterDetail. This API call is unique in that is gives you the ability to have Quick Base copy the parent record, and then copy various child tables or grand-child tables as you decide. This way - you can truly copy a record in your system and keep the relational aspects of it intact.
There are two common ways you can set up and utilize API_CopyMasterDetail.
Option 1 - Quick Base has a built in walk through to help you easily set up a button to invoke this API call on one of your tables.
Option 2 - You can configure the API call as a good old fashioned HTTP Request and use it in custom scripting, webhooks etc.
Both options will be discussed in detail below.
Option 1 - Using Quick Base's built in CopyMasterDetail setup
With that, you're done. If you end up making a mistake or change your mind later about any of the steps from above, you can simply delete your button and start again.
Option 2 - Write your own API call for a webhook or custom set up
There might be several reasons you go this route as opposed to the above.
The set up for API_CopyMasterDetail is similar to an AddRecord or EditRecord, so for simplicity we'll discuss it via the URL alternative that one might use in your own URL button or a GET request
The generic set up for the CopyMasterDetail url might look like below:
For brevity - we won't cover the initial set up and defining the target domain, target dbid or Authentication/apptokens here. For a more detailed breakdown of these, API_AddRecord and API_EditRecord go into them in more detail.
Beyond that, CopyMasterDetail has some unique parameters to this particular call
destrid - REQUIRED
The destrid is basically your way of telling Quick Base to create a new record, or copy the details of another. This will correlate above with step (3) in Option 1 - in regards to if you want to copy this exact record and its details - or copy detail records from a specific Project. There are two options with this, set destrid equal to 0, or set destrid equal to a specific record id in your table.
By setting destrid=0, you will copy that exact record and its children. So if you have this call on Project with Tasks, and destrid=0, you will get a brand new copied Project and all of its Tasks. If you set destrid=5, you will copy all detail records from another Project to Project ID=5.
sourcerid - REQUIRED
sourcerid is the specific record you want to actually copy. So if you want to copy an existing record to create a true copy, you would set this to the specific record you are on. If you are trying instead, to copy the details from a specific Project, you would set this to be the Record ID# of that particular template record. If there is a 'template' Project you set up, you would set your sourcerid to that particular Project, at which point it will copy the details from that template.
copyfid - REQUIRED
This is the field ID of an existing field that Quick Base will write the words 'copy of..' to name your copy. For example - this might be the field id of the field 'Project Name' in your table. If you are copying a record name 'Test Project', then your new Project created would be 'Copy of Test Project.'
recurse - OPTIONAL
Using this param makes your Copy recursive, meaning that it will copy your details details. By default - this is true, so if in our example of Projects -< Tasks -< Activities, having recurse=1 will copy all 3 levels, so Activities will also copy. With recurse=0, only Tasks will copy, and Details of Details (Activities in this example) will not copy. By default - the copy will default to recurse being true.
relfids - OPTIONAL
Relfids tells Quick Base which of your relationships you want to copy detail records for. With this, you can determine if all children get copied, or if only certain relationships do. Following a similar example from option 1, this is where you can set that you want to copy Projects and Tasks, but omit Documents, another child to Projects from following suit. The input for Relfids is a comma delimited set of Field IDs, that correspond to the relationships you want copied.
You'll notice that in every new relationship, Quick Base will create a new 'Report Link' field that helps display and link your children to your parent, used often to display embedded reports on forms. Those fields are relevant here, as they serve as the link for your API call to know which detail records to copy. You can pick and choose which relationships to copy by finding the field IDs of the specific report link fields in the relationships you want copied, and placing them in your relfids param. By omitting this value - Quick Base will default to copy any and all relationships.
With that configuration, you can have the building blocks of your CopyMasterDetail API call. If you want to try and test Option 1 before tackling Option 2, you can open up the field properties of the button that is created in Option 1 as a result, and you will be able to see the Quick Base set up they provide when you follow their steps as well.
For more information about the different types of API calls - view the full list currently in our Knowledge Base here
Author: Chayce Duncan (email@example.com)
Date Submitted: 5/9/2019