One button to create multiple child records

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

I have 5 buttons which create related records on 5 different tables. I'd like to create one button which can create all 5 records eliminating the need to click and save each related record. Please see the attached powerpoint for more information. 


Thank you

Photo of PAUL

PAUL

  • 112 Points 100 badge 2x thumb

Posted 3 years ago

  • 1
  • 1
Photo of Steven

Steven

  • 0 Points
There are a couple of ways you could do this, depending on how conditional you want the button to be.

Are you OK with the button checking for any child records and if there are none, then it adds all 5 child records and if there are any, then it does nothing (or throws up an alert saying "you already made these")? Basically "all or nothing".

Or do you need the button to look at each type (996, 1013, 1015 etc.) and only add the ones that are missing?
Photo of PAUL

PAUL

  • 112 Points 100 badge 2x thumb
After I've built an aircraft I create all 5 child records at the same time as my end users need access to all 5 of them.  So all or nothing works great.

The way I was thinking the logic would be something like:
If[# of 996's]=0, (Create 996, 1013, 1015, 1020, 1054), null)

So the idea is that if there are none, the button is visible and can create all 5, otherwise the button is hidden.
Photo of Steven

Steven

  • 0 Points
The "all or nothing" route can be done with a slimmed down version of this technique. 
http://www.quickbase.com/quickbase-blog/how-to-quickly-create-multiple-child-records-in-quickbase/

Since you are wanting to just create blank child records, your templates for each aircraft type would only consist of a couple of fields.
In your example you have the parent which would equate to "Projects" in the how-to above.Your aircraft types would be "Tasks".And you would need to create "Aircraft Templates" and the "Focus" table.

Let me know if you have any questions.
Here is an easy solution, especially since you already have your 5 buttons created. 

Make the field called [Add all children] be this URL formula field.


var text URLONE = [My URL button 1];

var text URLTWO = [My URL button 2];

var text URLTHREE = [My URL button 3];

var text URLFOUR = [My URL button 4];

var text URLFIVE = [My URL button 5];

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

// that last string will redisplay the record you are sitting on. if([# of 996's]=0,

$URLONE 
& "&rdr=" & URLEncode($URLTWO)
& URLEncode("&rdr=" & URLEncode($URLTHREE))
& URLEncode(URLEncode("&rdr=" & URLEncode($URLFOUR)))
& URLEncode(URLEncode(URLEncode("&rdr=" & URLEncode($URLFIVE))))
& URLEncode(URLEncode(URLEncode(URLEncode("&rdr=" & URLEncode($URLSIX)))))


)



// I edited the above to wrap it with an IF
Photo of PAUL

PAUL

  • 112 Points 100 badge 2x thumb
If I'm understanding the logic behind this essentially you are saying if([# of 996's]=0, click button 1,2,3,4,5 then return back to main form?

The issue with this is that the first time you click the button it does not save the respective child record only generates the child record and leaves you in edit mode.  Is there a way to change my individual button formulas to add the child record and save it? Below is the current formula for [My URL button 1]

If([# of 996's]=0, URLRoot() & "db/" & [_DBID_SA_M_996] & "?a=API_GenAddRecordForm&_fid_6=" & URLEncode ([Registration])& "&z=" & Rurl(),  URLRoot() & "db/" & [_DBID_SA_M_996] &"?a=dr&rid=" & [Maximum Record ID# of 996's])
You are not understanding what I am saying. That one button will create 5 child records and redisolay the Parent.

The formula I posted makes use of formula variables. So just change where I have put [My URL button 1] to each respectively of your existing buttons.


Well, actually I didn't  know what's in your buttons until your latest post. What needs to go into each of my 5 formula variables is just the part of the URL formula which creates the child record.

So it would be this code here

URLRoot() & "db/" & [_DBID_SA_M_996] & "?a=API_GenAddRecordForm&_fid_6=" & URLEncode ([Registration])

Like this

var text URLONE = URLRoot() & "db/" & [_DBID_SA_M_996] & "?a=API_GenAddRecordForm&_fid_6=" & URLEncode ([Registration]);

Then similar for the next 4 formula variables.
Sorry, correction

The API needs to be API_AddRecord
var text URLONE = URLRoot() & "db/" & [_DBID_SA_M_996] & "?a=API_AddRecord&_fid_6=" & URLEncode ([Registration]);
Photo of PAUL

PAUL

  • 112 Points 100 badge 2x thumb
You beat me to the answer, I had just figured it out too! Thank you for your support!

I was able to modify my individual buttons. Rather than using API_GenAddRecordForm, i used just API_AddRecord instead.  My [Add All Children] button is now working.

If([# of 996's]=0, URLRoot() & "db/" & [_DBID_SA_M_996] & "?a=API_AddRecord&_fid_6=" & URLEncode ([Registration]),  URLRoot() & "db/" & [_DBID_SA_M_996] &"?a=dr&rid=" & [Maximum Record ID# of 996's])
But do you now have all 5 being created in one click?
Photo of PAUL

PAUL

  • 112 Points 100 badge 2x thumb
Yes all 5 are created in 1 click. The only issue I have is if I'm using the individual buttons it takes me to the XML response page.  Now that we have 1 button do with the functionality of all 5 then we no longer would be using the individual buttons to create, only to display records after they have been created.
Right, if you want to make another 5 buttons which would work independently,

The format would be different.  I posted an app in the Exchange called URL Formulas for Dummies, which has an explanation.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,224 Points 20k badge 2x thumb
@Mark

I can't believe you didn't use the "Redirect Mark" technique for this native solution.

What is the Redirect Mark Technique
https://quickbase-community.intuit.com/questions/1431313-what-is-the-redirect-mark-technique

MS: "Yup, that was a pretty useful tip for the next time I need to make a button to create a standard set of records.  Thx for the Syntax example." See: https://quickbase-community.intuit.com/questions/1428503-automatically-add-date-records
Photo of elandirayan

elandirayan

  • 10 Points
Hi Steven,

  I am also having a similar type of requirement.   I have my requriement below.

I have a field called total Budget for each item in parent table along with start date and End date. While click on saving the parent record I need to create a child record dynamic.

if suppose an parent is created with start date as 10/1 and end date as 12/1 and the Total budget is 15000, then i need to create three child record for each month with value as 5000.

the date is dynamic. Also the child record they can edit later if requried. Also is there any way to create a unique field with combination of multiple fields.
Photo of Christopher

Christopher

  • 2 Points
Hi, Mark, I used your suggested answer above to get me heading in the right direction. My scenario is slightly different in that I don't create a new child record if the user doesn't fill in any data for them. They have the option of inputting 10 records, but may only fill out 4 or 5. However, that causes my redirect URL at the end to not function properly for some reason. Is there a way to redirect the user back to the app homepage if they don't fill out all 10 records? I can create a new thread if need be. Thanks
I think that a new question would be best.
Photo of Christopher

Christopher

  • 2 Points