How can I use "Copy Master & Detail Record" function in Quickbase to only copy a specific subset of child records from a master template?

  • 0
  • 1
  • Question
  • Updated 1 year ago
  • Answered
How can I use the "Copy Master & Detail Records" function in Quickbase to only copy a specific subset of child records from a master template?

I have a Master Project record with 40 child records and I have a button with the following URL formula, that copies and relates all 40 child records (tasks) to a new project record: "javascript:void(copyMasterDetailButtonHandler('&relfids=72&recurse=false&sourceRID=3&destrid=" & [Record ID#] & "', 'bmzg6sw35'))"

I would like to create 3 buttons that copy and relate only the tasks associated with a specific field value (for button 1, [Department] = X and for button 2, [Department] = Y, etc.). I suppose I could create multiple templates and use the wizard in Home -> Settings -> App Management -> "Copy Master and Details Records" to create different buttons for each template  but that seems messy.

Any ideas on how I can use the "Copy Master and Details Records" wizard with a more specific criteria or create a custom URL?

Thanks for your help!
Photo of Michael Santiago

Michael Santiago

  • 132 Points 100 badge 2x thumb

Posted 1 year ago

  • 0
  • 1
Photo of Chuck Grigsby

Chuck Grigsby

  • 1,978 Points 1k badge 2x thumb
 I recently finished that does this. Whenever a new record is created it uses the CMD but as the user adds/edits the record various checks occur and will add more child records. Master is a request and children are Checklists, Tasks, Assignments and Docs. Its custom scripted beyond the CMD but works well. If you want you can reach out directly at Chuck@Chuck.Support if you want to see a demo of the app. Good luck with your project Michael!
Photo of Michael Santiago

Michael Santiago

  • 132 Points 100 badge 2x thumb
Thanks for the quick reply Chuck. That solution sounds pretty dynamic and may be more robust than I need.

I'm just looking for a way to loop through the children records of my master template and copy only the ones that have 1 or 2 specific field values over to my new record. For example, if([Department] = X, copy and relate that task record with the new project record).

Just not sure if that can be done with CMD or another function or if it requires more customized API calls via webhooks?
Photo of Chuck Grigsby

Chuck Grigsby

  • 1,978 Points 1k badge 2x thumb
I use IOL and jquery for the API calls. My app definitely has a lot but they're really just copy paste after the first couple conditions. Happy to show you and send a few examples you could tweak and use for yourself. I know you only have a few things later but if later on you need it to scale you'll have everything you need already. 
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 53,570 Points 50k badge 2x thumb
Michael,
I'm not quite sure what our conditions are for copying and whether they are so limited that you can have a different button per situation, or you need to be able to enter some data to control what needs ot be copied over.

In general, without knowing more about your specific use case, I will say that this can be done natively using a saved table to table copy and some other native setup which is probably too difficult to explain on the form unless you are pretty good at QuickBase.

If you describe your use case in a bit more detail I can estimate how long it would take to set that up and offer a general explanation of the steps
Photo of Michael Santiago

Michael Santiago

  • 132 Points 100 badge 2x thumb
Thank you for the reply.

My conditions for copying child records are fairly simple and flexible. There are 3 different phases of a project and 3 corresponding departments for each phase. The child records have a drop down field called [Department]. I'd like to dedicate a button to each of the 3 departments/project phases (i.e. I'd like to create a button that just copies the 5 tasks that have "Department A" in the [Department] field and another button that just adds the 15 tasks with "Department B" in the [Department] field...)

Alternatively, I have a field called [Task Order] that is numbered 1-40 for each task, which I use to sort the embedded task report in the project record. So I could elect to copy child records where [Task Order]<6 for the "Department A" button and copy records where ([Task Order]<21 AND [Task Order] >=6) for "Department B"... 

As a last resort, I could create multiple templates and use the wizard in "Copy Master and Details Records" to create different buttons for each template but my gut tells me there is a cleaner and more streamlined way to do this. Would hate to have to update and maintain multiple templates and protect them all from being tampered with when my app goes live.

Thanks again and look forward to your thoughts.

Michael
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 53,570 Points 50k badge 2x thumb
If you want a solution not involving outside consulting help, I suggest just making three buttons and controlling them with form rules and / or in the formula itself. 

ie

IF([Department]= "XYZ", 
"javascript:void(copyMasterDetailButtonHandler('&relfids=72&recurse=false&sourceRID=3&destrid=" & [Record ID#] & "', 'bmzg6sw35'))"
)

Alternatively, I do have a native solution not involving javascript, but it would probably take an hour of consulting time one on one to explain it.

Basically you would push a formula URL button which would populate a two fields called [Focus Department]  and [Focus project] in a single record with Record ID # 1 in in a table called User Focus. That would then be looked up to a table of tasks. Then that same URL button would next execute API_RunImport to  copy the records from a table of tasks which match the Department into the child tasks table for the focus project.

Then the URL formula button would redisplay the project.

The button would look like this

$URLONE 
& "&rdr=" & URLEncode($URLTWO)
& URLEncode("&rdr=" & URLEncode($URLTHREE))
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 28,144 Points 20k badge 2x thumb
I should mention that I have been doing a lot of work recently using the new Async / Await feature in JavaScript that is ideal for complex tasks that would involve a lot of AJAX calls.

Most script solutions involve a handful of AJAX calls for which jQuery alone is perfectly adequate. I have written hundreds of such solutions using no more that say six AJAX calls. But recently some clients have brought to me problems that might involve hundreds of AJAX calls sometimes recursive in nature. Whole new schemes of writing JavaScript need to be created and it takes a dozen or so such tasks to get a good handle of how to implement these solutions. But the benefit is enormous as the resulting code is quite short and reads as if it was synchronous.

Here is a tiny example of an asynchronous function doit() that fetches two URLs provided as parameters:
var doit = async function (url1, url2) {
  var response1 = await fetch(url1);
  var xml1 = await response1.text();
  var response2 = await fetch(url2);
  var xml2 = await response2.text();
}
You will note that there are no callbacksthen() methods or unnecessary indention used and the code reads as if it was synchronous (executes line after line) even though it is asynchronous. This is because the async function doit() suspends itself while it is waiting for the fetch response to arrive and resumes execution afterwords - all without blocking other running tasks or locking up the browser's display.

If you need a script solution to your problem feel free to contact me off-world.
(Edited)