How do I create a button on a form that will save the current record, copy some of the fields to a new record, and redisplay the new record in edit mode?

  • 0
  • 2
  • Question
  • Updated 9 months ago
  • Answered
Photo of Krissy

Krissy

  • 100 Points 100 badge 2x thumb

Posted 4 years ago

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

QuickBaseCoach App Dev./Training, Champion

  • 65,168 Points 50k badge 2x thumb
This can be done natively except not the initial Save. You would need to be in View Mode having saved the record.
Photo of Krissy

Krissy

  • 100 Points 100 badge 2x thumb
Okay I can work with that....
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 65,168 Points 50k badge 2x thumb
Actually sorry, I need to take that back.  The choices are either to push a button to put up an Add Record Form with some of the fields filled in and then user would do any additional data entry and save, or alternatively push a button to create the copied record and display it, but not be in edit mode.
Photo of Krissy

Krissy

  • 100 Points 100 badge 2x thumb
Okay, let's try the first option.
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 65,168 Points 50k badge 2x thumb
There are two ways to go here. Low Tech and high Tech.

Low Tech

You will notice that when you use the More button while viewing a record and click to Copy this Record, the URL you see looks like this


mycompany.quickbase.com/db/xxxxxx?a=GenCopyRecord&rid=770

So the low tech solution is just to make a URL formula button to make that URL

The formula would be

URLroot() & "db/" & dbid() &  "?a=GenCopyRecord&rid=" & ToText([Record ID#])

When you use that option by default all the data entry fields on the form will copy across to an Add Record Form.  If you do not want certain fields to Copy across then you individually go to each field that you do not want to copy across and uncheck the property

Auto-fill Copy the value when using "Copy this Purchase Order" to add a new Purchase Order

The best way to quickly get to the field Properties is to right click near the field on the form.

The only downside of this method is that if any fields on the form are set to be Read Only or are not visible on the form, I don't think that they will copy across.

Higher tech

So the more reliable way would be to use an API

Here is an example

URLRoot() & "db/" & Dbid() & "?act=API_GenAddRecordForm"
& "&_fid_12=" & [Purchase Order #]
& "&_fid_42=" & URLEncode([Component or Bulk item?])
& "&_fid_38=" & [Related Bulk item Master]
& "&_fid_24=" & [Related Component]
& "&_fid_28=" & ToText([Line Item Cost Override])
& "&_fid_53=" & URLEncode([PO Line Comment])

Note that when you use this method you are building a URL, and URLs may not have spaces or specials characters in them.  So where there might be a strong that you are putting into a field, which might have special characters or spaces you need to URLEncode as I have done above.  The "fid's" are the field ID numbers.

Lastly, if you did decide that you wanted to actually create the record and display it to the user, then you could do this

URLRoot() & "db/" & Dbid() & "?act=API_AddRecord"
& "&_fid_12=" & [Purchase Order #]
& "&_fid_42=" & URLEncode([Component or Bulk item?])
& "&_fid_38=" & [Related Bulk item Master]
& "&_fid_24=" & [Related Component]
& "&_fid_28=" & ToText([Line Item Cost Override])
& "&_fid_53=" & URLEncode([PO Line Comment])
& "&disprec=1"


 


Photo of Krissy

Krissy

  • 100 Points 100 badge 2x thumb
Thank you!  I'm almost there..... I'm running into one problem.  I went with the high tech scenario option 1 - here is my formula:  

URLRoot() & "db/" & Dbid() & "?act=API_GenAddRecordForm"
& "&_fid_85=" & URLEncode([PO # (on PO form) - Lookup])
& "&_fid_23=" & URLEncode([Item Number (on ITEMS form) - Lookup])
& "&_fid_6=" & [Inspector]

Field 23 is not populating.  It's a look up field that relates the inspection back to the item being inspected.  Any idea why that isn't populating?  FID 85 is also a look up field and that one is populating correctly.  Could it have something to do with the relationship between those 2 fields?
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 65,168 Points 50k badge 2x thumb
Glad you are getting close.  We will have you being an API whiz before you know it.

You cannot populate a lookup field.  So what you need to find is the field [Related Parent] for where the lookup came from - ie the "reference field' on the right side of the relationship and populate that field.  Then ALL the lookups for that relationship will come down automatically.
Photo of Krissy

Krissy

  • 100 Points 100 badge 2x thumb
I don't know about being a whiz but I'm atleast at novice level now! I found the correct reference field and it's now working. Thank you for your help!
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 65,168 Points 50k badge 2x thumb
yay! Well done.
Photo of Matthew

Matthew

  • 60 Points
Instead of copying the information to a new record, is it possible to copy data in specific fields to an entirely different form?
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 65,168 Points 50k badge 2x thumb
Yes, you can click a record in one table and pop up an Add Record form in another table.  Just change the part of the formula which identifies the [_DBID_ of the table]
Photo of Matthew

Matthew

  • 60 Points
So in the formula, the &"&_fid_6=" would be the field ID for the new record on form "B"? while the string next to it: & [Inspector] would be the field of the pre-existing record on form "A"?
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 65,168 Points 50k badge 2x thumb
Exactly!
Photo of Matthew

Matthew

  • 60 Points
I'll give it a shot, Thanks!
Photo of Paul Vorster

Paul Vorster

  • 576 Points 500 badge 2x thumb
Thank You Mark, great solution.