Forum Discussion

HowardFu's avatar
HowardFu
Qrew Cadet
5 years ago

Button to Create Record in Edit Mode

Hello,

I'm trying to create a formula URL button that creates a new record and displays it in edit mode. Is this possible? If so, what would the code be?

------------------------------
Howard Fu
------------------------------

7 Replies

  • DonLarson's avatar
    DonLarson
    Qrew Commander
    Howard,

    You can accomplish this using API_GenAddRecordForm .  I suggest that you a Formula Rich Text.  I am assuming that you want to add a Child Record to the Parent that User is currently on.


    // Images
    var text IMG  =     "<img src=https://images.quickbase.com/si/48/045-lock.png>"

    // URLs
    var text URLGenAdd =
      URLRoot() & "db/" & Dbid() &
      "?a=API_GenAddRecordForm&_fid_XXX=" & URLEncode ([Record ID#])&
      "&z=" & Rurl();

    // User Interface
    "<a href=" & $URLGenAdd &  $IMG &  "</a>"


    You need to make a few modifications
    • Pick an image that you want to display for this.  The one above is from the Quick Base Image Library.  The one I have included is of a Lock.
    • Edit the URLGenAdd variable replacing the XXX with number of the Related Parent Record.   You find this in the fields of the Child Table where your record is being created.

    This will give you an image that the User clicks on, creating a record related to the one they were just on and being able to edit the values from the default add form.




    ------------------------------
    Don Larson
    Paasporter
    Westlake OH
    ------------------------------
    • HowardFu's avatar
      HowardFu
      Qrew Cadet
      HI Don,

      I'm trying to create a record in the same table from an existing record. The reason I want to do that is because we use the mobile interface to receive packages. Each packages gets a unique "Receiving Number". When I am done filling out the information for a received package and want to move onto the next new package, I want to click a button from the record I just finished to create a new record that displays the new "Receiving Number" (which is an auto-generated number based on record ID) but also display it in edit mode. Currently I have:

      URLRoot()&"db/"&Dbid()
      &"?act=API_Addrecord"
      & "&disprec=1"

      Right now, when I press the button, it will create a new record and show the new "Receiving Number" . I have to click edit to start editing. I'm just trying to save a step by displaying the record in edit mode.

      ------------------------------
      Howard Fu
      ------------------------------
      • AdamKeever1's avatar
        AdamKeever1
        Qrew Commander
        There is a way to do this Howard. You will need another table to summarize the Maximum Record ID# from your data table.

        Here is what I did. I made two tables:

        I added a single record to the MAX RIDs table. No new fields needed, just add a single record.

        Then I added a formula numeric field called [key] to the Records table and gave the formula a value of 1. This relates all records to the single record in the MAX RIDs table.

        Next I created a one MAX RIDs to many Records relationship using the [key] field as the reference field and then added a summary field for the Maximum Record ID# and a lookup field for the Maximum Record ID#.

        Then I added a formula numeric field with the following formula:

        [key - Maximum Record ID#] + 1

        Then lastly I added a formula rich text field for the button with the following formula:

        "<a class='Vibrant Success' style=\" text-align: center; border:1px solid #6BBD57; background-color:#6BBD57; \"href='"& URLRoot() & "db/" & Dbid() & "?act=API_AddRecord&apptoken=YOUR_APP_TOKEN_GOES_HERE"& "&rdr=" & URLEncode(URLRoot() & "db/" & Dbid() & "?a=er&rid=" & [MAX RID plus 1] & "")&"'>YOUR_BUTTON_NAME_GOES_HERE</a>"

        You can see the actual Record ID# on the far left and the lookup Record ID# on the right with the index field that adds 1 to the maximum Record ID#. This is needed for the redirect in the button or else it would not open the correct Record ID# for at the time the code is executed, the new Record ID# does not yet exist.

        Here is the table:

        and here is the record that is created then opened in edit:


        ------------------------------
        Adam Keever
        ------------------------------