How to Auto Save Child Record While in Parent Record Without Leaving Parent Record?

  • 0
  • 1
  • Question
  • Updated 4 years ago
  • Answered
I'm in the parent record and have a button to create a child record in another table that pulls two fields from the parent table. Could I change the button formula so that I can create the child record and have it saved without ever having to navigate away from the parent table? Since the child record is pulling info from the parent I don't need to edit anything in the record.

Details

Parent table = Sites

Child Table = Unique Visitors

Child Table is pulling the fields Unique Visitors and Unique Visitors Date.

Photo of shoutoutlori

shoutoutlori

  • 0 Points

Posted 4 years ago

  • 0
  • 1
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 65,542 Points 50k badge 2x thumb
You have two choices.

If you want to create a child on the fly while adding a Parent, then set the Advanced properties for the Parent table and check the box


"Save parent record automatically when a child record is created".

Then just use the usual Add Child button and save and you will be returned to the Parent record.


Alternatively, If you want to be able to add a Child with 1 click but AFTER the Parent has already been created, then in View or edit mode show a formula URL button like this

var text URL =
URLRoot() & "db/" & Dbid () & "?act=API_AddRecord&_fid_xx="  & totext([Record ID#]);

"javascript:" &
"$.get('" &
$URL &
"',function(){" &
"location.reload(true);" &
"});"
& "void(0);"

Replace the xx with the field ID # for [Related Parent] on the child table's field list.
Photo of shoutoutlori

shoutoutlori

  • 0 Points
So the first answer you have is what I had already set up. My parent record would auto save whenever I added a new Unique Visitor (Child Record). It would then take me to the edit view of the new child record, I'd have to save and then it would take me back to the parent record.

The second answer seemed to work but then I realized it's just updating the current child record and not adding a new child record. Is there no way to automatically add a new child record without having to go into the edit screen of said new child item?
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 65,542 Points 50k badge 2x thumb
Actually, the second method creates a child and then refreshes the Parent page.  It does not just put up an Add Record form, it actually creates the child and then refreshes the Parent record, so you would instantly see it on an embedded report on the Parent.

However, if you were in edit mode and had "dirtied" the record without saving, there would be a pop up asking if you wanted to save the changes to the Parent record. But in view mode and in edit mode with no unsaved data entry made, it will just quietly create the child and refresh.
Photo of shoutoutlori

shoutoutlori

  • 0 Points
So using the following code in the URL button does not work for me (6 is the ID of the related site in the child table):
var text URL =
URLRoot() & "db/" & Dbid () & "?act=API_AddRecord&_fid_6="  & ToText([Record ID#]);

"javascript:" &
"$.get('" &
$URL &
"',function(){" &
"location.reload(true);" &
"});"
& "void(0);"

It only updates an existing child record with the updated information in the parent table. It does not create a new child record. I have since deleted the already created child record and the URL button will still not create a new record. Even if the information in the parent is saved and then I press our new button, it will still not generate a new record.
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 65,542 Points 50k badge 2x thumb
Sorry, this part was wrong.

var text URL =
URLRoot() & "db/" & Dbid () & "?act=API_AddRecord&_fid_6="  & ToText([Record ID#]);

It needs to read

var text URL =
URLRoot() & "db/" & [_DBID_of your child table found in Advanced properties] & "?act=API_AddRecord&_fid_6="  & ToText([Record ID#]);


e.g. the format for the child table reference would be like
[_DBID_CHILD_TABLE]