Can I save changes to a parent record as the first step in a URL-formula in a child record?

  • 0
  • 1
  • Question
  • Updated 3 years ago
  • Answered
I have two tables: Accounts (parent) and Contacts (child).  In the Accounts form, I have a table (report link) showing all of the related Contacts.  I added a Formula-URL button to the embedded Contacts table that applies the data from a chosen Contact to the matching fields on the Account form.  Everything works if the parent record hasn’t been updated.  However, if the parent record has been updated, the popup for “Confirm Reload” appears when you click the button.  If you chose to reload, the previous updates to the parent record are not saved.

How do I save the updates to the parent record before running the API_EditRecord?  Here’s my Formula-URL in the Contacts table:

var text url=

URLRoot()& "db/XXXXXXXXX?a=API_EditRecord" &
"&rid=" & [Related Account]&
"&apptoken=xxxxxxxxxxxxxxxxxx"&
"&_fid_39=" & [Name]&
"&_fid_40=" & [Email]&
"&_fid_41=" & [Phone]&
"&_fid_42=" &[Job Title];

"javascript:" &
"$.get('" &
$url &
"',function(){" &
"location.reload();"&
"});" &
"void(0);"
Photo of Andrew

Andrew

  • 46 Points

Posted 3 years ago

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

QuickBaseCoach App Dev./Training, Champion

  • 65,280 Points 50k badge 2x thumb
Can you live with only showing that button when the Parent is in View Mode?  Then you will not have a problem. I assume that the button is a field in the embedded report. You could have an alternate embedded report link to show in view mode with the button, and the one for edit, without.
Photo of Andrew

Andrew

  • 46 Points
Unfortunately, no.  The records are almost exclusively used in Edit Mode and there are usually changes in other fields on the form.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,044 Points 20k badge 2x thumb
Instead of "location.reload();" use "saveButton.click();" 

"javascript:" &
"$.get('" & 
$url & 
"',function(){" &
"saveButton.click();" &
"});" &
"void(0);"

Test in Chrome first.
Photo of Andrew

Andrew

  • 46 Points
Thanks, this is great! Is there something that you can add so that it will redirect back to editing the original record?
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,044 Points 20k badge 2x thumb
Add theses two statements:

"javascript:" &
"$.get('" &
$url &
"',function(){" &
"RedirectURL.value = document.location.href;" &
"document.forms.editform.rl = '';" &
"saveButton.click();" &
"});" &
"void(0);"

Test in Chrome first and continue with other browsers.

I hesitate to continue building the formula like this as you should get out of the formula language as quickly as possible and avoid all the escaping non-sense. But curiosity got the better of me and I am sure the crows will be flying over my head the rest of the day. And Mark is probably going to figure this out and we are in for another decade of mixing JavaScript within QuickBase formulas.

Why not just throw out the formula language and replace it with pure unadulterated JavaSciprt?

UPDATE: You may not need that final void(). Test it and let us know.
Photo of Andrew

Andrew

  • 46 Points
It still redirects to the report, not the edit record.  I tried with and without the void.  I'm pretty bad with JavaScript, so I wouldn't know what to do.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,044 Points 20k badge 2x thumb
>It still redirects to the report, not the edit record.

I omitted the ".value" part in the rl assignment statement. Try this:

"javascript:" &
"$.get('" &
$url &
"',function(){" &
"RedirectURL.value = document.location.href;" &
"document.forms.editform.rl.value = '';" &
"saveButton.click();" &
"});" &
"void(0);"
Again, test in Chrome first, then other browsers and also test by eliminating the void(). Let us know what happens.
Photo of Andrew

Andrew

  • 46 Points
This works beautifully!  Thank you so much.