Help with copy Master detail records button?

  • 1
  • 2
  • Question
  • Updated 3 years ago
  • Answered

I have created a Copy Master detail records button.....I have Table A (Parent) and Table B (Child)......I would like to copy a Table A Record with its related Table B child records.....When I click the [Copy Master detail records] I get an error issue:

"CopyMasterDetails" does not allow unique fields.

I assume this is due to the fact that I'm not using Quickbase's standard [RecordID] as my key field within Table A....I have a [text] field as my key field..and I guess when I click [Copy Master detail records]....quickbase is trying to copy my key field (which must be unique) into the new Parent record....

Any suggestions on how to overcome? Thanks

Photo of rocketc

rocketc

  • 824 Points 500 badge 2x thumb

Posted 3 years ago

  • 1
  • 2
Does that text field really have to be your Key field?
Photo of rocketc

rocketc

  • 824 Points 500 badge 2x thumb
Yepper.
I think that then that you would need to create the new parent either with the button or URL equivalent to copy a record (the link that you see when you are on a record and use the More button, and then Copy this record.  

Alternatively you can use the API AddRecord and have a long URL formula to specify each field to be copied over.

Then you would need to the Copy Master detail URL to import the child records from one record to another.  I happen to be doing a project now that may require me to do those same steps due to a mysterious problem where the usual Copy Master Detail API is not working.  The trick will be to find an elegant way to specify the Parent record for who's children should be copied in.  I think I know what approach i will use - if you like you can contract me via the information in my Profile and when  I get it working maybe over the weekend, I can show you want I did.
Photo of rocketc

rocketc

  • 824 Points 500 badge 2x thumb
Mark, All I really want to do with the "copyMasterDetails" ---- is copy just the child records of a selected Parent record --I do not need to actually copy any data from the "Parent record" getting copied.....If it would be possible I could create my New Parent Record.......and from this new Parent Record .....maybe have a look-up field (parent table having a relationship with itself) ....and at this point select the "Parent Record" that I would like to copy the child detail records of.....and then have a [Add detail Records] button.......have no idea what that formula would look like.......but it would......copy the details of the Parent selected in the look-up.......is this clear as mud?
Yes, that can be done.  

You can lookup the help into on the API to Copy Master detail here http://www.quickbase.com/user-assistance/Default.html#apicalls.html and look down the list for Copy Master Detail.  Then you can read the parameters and then skip down to the URL format at the bottom.

So, you you would do a lookup to get the Parents whose records are to be copied to be a lookuop field onto the record.

Then the formula (not tested) would be

var text URLONE =
URLRoot() & "db/" & dbid() & "?act=API_CopyMasterDetail"
& "&Destrid=" & ToText([Record ID#]) // ie the target to copy to is the Record ID I'm sitting on now
& "&Sourcerid=" & ToText([Record ID# of the Source Parent])
& "&refilds=41"; // the number 41 gets replaced with the field ID of the Report Link field on the right side of the relationship for the child table records to be copied in.

var text URLTWO=
urlroot() & "db/" & dbid() & "?a=dr&rid=" & ToText ([Record ID#]);

$URLONE
& "&rdr=" & URLEncode($URLTWO)
Photo of rocketc

rocketc

  • 824 Points 500 badge 2x thumb
Mark,

I really appreciate your help. I was not able to get it working......I got the error below.....

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<qdbapi>
<action>API_CopyMasterDetail</action>
<errcode>2</errcode>
<errtext>Invalid input</errtext>
<errdetail>
CopyMasterDetail does not allow looping relationships
</errdetail>
</qdbapi>
Oh, right.  Sorry.  You cannot have a table related to itself and use CopyMaster Detail.  I think that the only option is to have the user Key the Parent Record ID# into a field.  I know that is not so User friendly, considering that your Key field is the one that might be a meaningful number to the Users.

There is an alternative to have the user select a Parent record and then be able to copy from that selected Parent into another record, but the method is too complicated to explain on this forum, and would take me about an hour of consulting time to get working for you.  I suggest that you contact me off line via the information in my profile if you want to talk about that.
Photo of rocketc

rocketc

  • 824 Points 500 badge 2x thumb
Mark, I got it working using the URL formula below.......

"javascript:void(copyMasterDetailButtonHandler('&relfids=[ReportLinkfieldID]&recurse=false&destrid=" &[Record ID#]&"&sourcerid=" &[SourceRecord ID#]& "', 'bkyu9yauw'))"

[SourceRecord ID#] -- via look-up
'bkyu9yauw' = tableURLid
Fascinating, actually - thx for letting me know.