Can I use the add master detail template buttons to 1) Copy the master record AND 2) Copy detail records from a separate template.

  • 0
  • 1
  • Question
  • Updated 4 years ago
  • Answered

I can use the Copy Master detail records to copy a Record with its related child records.

"javascript:void(copyMasterDetailButtonHandler('&relfids=576&recurse=false&copyFid=615&destrid=0&sourcerid=" & [Projection ID#] & "', 'biunwxxx'))"

And separately I can use the Master Details wizard to add child records from a different record (ie a template record)

"javascript:void(copyMasterDetailButtonHandler('&relfids=576&recurse=false&sourceRID=768&destrid=" & [Projection ID#] & "', 'biunwxxx'))"

What I want do to those copy the Parent record AND add child records from the template.   (so child records are created but fields unpopulated while parent record is fully populated).

Thanks for any suggestions.

Photo of Mike

Mike

  • 0 Points

Posted 4 years ago

  • 0
  • 1
Are you asking if this can be done all in one click?  

In two clicks it's easy. Just make a Copy Master detail button and when you make it, specify that the Child records are to always come from the same parent record.  Then put the button on your Parent record but hide it once the parent has children.
Photo of Mike

Mike

  • 0 Points
Was hoping for a one click solution...
Photo of Mike

Mike

  • 0 Points
Hi Mark - I was hoping for a one click solution, but have implemented the 2 step solution for now.

Related question: When i add the detail records from the template I get a prompt that says "records" have been added and then I am put into the "display" view for the parent record.  Any easy way to instead go to the "Edit View" of the parent record (so users can immediately edit the embedded report)
Yes, you can use the API method instead.
You will need to read the help text on the API for API_CopyMasterDetail

Here is an example

var text URLONE =URLRoot() & "db/" & Dbid() & "?a=API_CopyMasterDetail"
& "&apptoken=xxxxxx" if you are requiring app tokens.
& "&destrid=" & ToText([RecordID#])
& "&sourcerid=" & "insert the fixed record id of the source record here")
& "&relfids=208"; // the rel fids are the field ID's of the report link fields on the relationships that you want to have imported.  They
can be comma separated, but it sounds like you just have 1 child table to be imported.

var text URLTWO = URLRoot() & "db/" &   Dbid() & "?a=er&rid=" & totext([Record id#]);  // the er will land you in edit mode.

$URLONE
& "&rdr=" & URLEncode($URLTWO)


I have not tested this, but it should work.
Photo of Mike

Mike

  • 0 Points
Thanks Mark - that definitely worked and is a super help.   This is for the 2 step process - could I not use something similar for a one step process (so first step is to copy the current record without child records, and then subsequent steps are as per your code above?
Photo of Mike

Mike

  • 0 Points
And one more note - I see that if I click this button with your new code before I have save the parent record, I get this error:

<qdbapi>
<action>API_CopyMasterDetail</action>
<errcode>2</errcode>
<errtext>Invalid input</errtext>
<errdetail>CopyFID required</errdetail>
</qdbapi>

Issue apparently is that there is no FID available to copy for the current Record ID (since it has not been save yet).   But is there a way to make saving the current record the initial step in the code?
no
Well, when I say "no" I mean using native QuickBase with no scripting in javascript.

There is a way to get Predict the Record ID, but if you are in a multi user environment, there is a risk.  You could have Table that counts the max record ID of the Parent table.  Add just Just 1 record with record id =1. Then on the Parent table where the button lives you have a reference formula field with a formula of 1 and then make a relationships and then Summary field of Max record ID#. Then look that up down to the Parent.  So then you know the next record ID will be max plus 1.

But if the user is sitting on a record for any length of time, the URL is frozen in place.  So other users could create more Parents and then the URL will not be fresh and not have the latest summary max of Record ID's that exist.