View Only
  • 1.  API button to add new parent record

    Posted 07-16-2022 21:08
    Hello,  I'm wanting to add an API button in a child table that would add a parent record and also add the parent record id to the related field in the child record.
    Basically the same thing that adding a record from a record picker does but pre-populate fields in the parent record. Is this possible?
    Thanks in advance for any advice!

    Sam Rettig

  • 2.  RE: API button to add new parent record

    Posted 07-16-2022 22:29
    Before API Gods reply , I think your button will be combination of two 

    1. API_Add record to add a parent record
    2. Get the record ID of the newly added parent record
    3. Redirect back to to current child record
    4. API_edit record to edit the child record and add related parent record ID 

    I don't know how to do #2

    Pipeline can easily resolve this ,but it would be want to see how API Gods resolve this

    Prashant Maheshwari

  • 3.  RE: API button to add new parent record

    Posted 07-17-2022 05:40
    Edited by Prashant Maheshwari 07-17-2022 06:04
    APIGods still are needed to resolve this, but some progress 

    I correct myself , I don't know how to achieve 4 as I've read at multiple place %%rid%% doesn't like to be URLEncoded in anyways, 

    • Below code creates a child
    • Comes back to child , edits it  . Please see notes with start with // 
    • Returns back to child record
    • AppToken were disabled during my testing, you need to enable these

    var text rd="%%rid%%";

    // Assuming you start from child record, This URL is to come back to the child and edit edit to enter parent id

    var text urltwo=URLRoot()&"db/" &Dbid()& "?a=API_EditRecord"
    //& "&_fid_8="&$rd --> This keeps failing as we cannot Record ID of parent , but works for any other field
    & "&rid="&[Record ID#]

    // This URL takes you to parent table and creates a new record, notice the dbid is hardcoded . The part which works

    URLRoot()&"db/"&"bsguktwqs"&"?a=API_AddRecord"& "&_fid_6=Gobaby"
    & "&rdr="&
    // Next URL BEGINS to go child and edit

    // Last URL with two encodes to come back to child ID after editing it back 
    & URLEncode("&rdr="&URLEncode(URLRoot() & "db/"&Dbid()& "?a=doredirect&z=" & Rurl()))

    Prashant Maheshwari

  • 4.  RE: API button to add new parent record

    Posted 07-17-2022 20:02
    I think there are two methods.  @Prashant Maheshwari 's post reminded me of the %%rid%% technique.

    If the goal is to Create a parent record with no data entry from the user, then you would use a regular API_AddRecord API (post back if you need help with that) and populate a field called  [Record ID# of Originating Child] with the Record ID# of the Child record that you launched from.

    Then create a Pipeline to trigger on Add Record where the [Record ID# of Originating Child] is >0 to edit the Child record for that Record ID# and put the Record ID# of the Trigger Added Parent record into the field for Related Parent.

    There will be a bit of a delay while the Pipeline runs.  If you needed a faster reaction time,  I think that you could use an "old fashioned" webhook or Action to update the child record as they will trigger very fast.

    .... now if your intent is to put up an AddRecord form  and have the user fill in some fields and manually save, then you could have a simple Add Record API and once again populate a field in the Parent Record with the Record ID# of the Originating Child.

    The initial Add Record API would just be this.

    URLRoot() & "db/" & [_DBID_PARENT] & "?act=API_GenAddRecordForm"
    & "&_fid_250=" & [Record ID#]  // populating the field called [Record ID# of the Originating Child]

    But then instead of having the user save normally, you would get the user to click a special formula Rich Text button with this code

    var text RID = "%%rid%%";

    var text EditChildToConnectToThisParent = URLRoot() & "db/" & [_DBID_CHILD]
    & "?act=API_EditRecord&rid=" & [Record ID# of Originating Child]
    & "&_fid_7=" & $RID;

    var text DisplayNewParent = URLRoot() & "db/" & [_DBID_PARENT] & "?a=dr&rid=";

    var text URL =
    & "&rdr=" & URLEncode($DisplayNewParent) & $RID;

    "<a class='SaveBeforeNavigating' data-replaceRid=true style=\"text-decoration:none; background: #4b7097; border-radius: 5px; color: #ffffff; display: inline-block; padding: 0px 0px 0px 0px; width:100px; text-align: center; text-shadow: none; border: 2px solid #030404; font-size: 12px \"href='"
    & $URL
    & "'>Display Parent with Child Attached</a>"

    //NOTE: The %%RID%% does not seem to like being URLEncoded.

    But a better suggestion is to launch from the Child with this code here.

    URLRoot() & "db/" & [_DBID_PARENT] & "?act=API_GenAddRecordForm"
    & "&_fid_250=" & [Record ID#]
    & "&ifv=1"

    .. what extra suffix will do that will do is take away the save button (along with all the header stuff)  and force the user to save with the provided Rich Text Formula button.

    The Rich Text formula button will land the user on the Newly created parent and the child will be attached in the Report link field with it displays.

    You can, of course play with the parameters of the Rich Text button to control the size of the font and the colour of:
    the button,
    the words,
    and the border. 

    Mark Shnier (Your Quickbase Coach)

  • 5.  RE: API button to add new parent record

    Posted 07-17-2022 20:27
    Thank you very much Mark and Prashan! I will try the suggestions and let you know how it goes!

    Sent from my iPhone

  • 6.  RE: API button to add new parent record

    Posted 07-18-2022 00:24

    HI @Mark Shnier,

    ​You are right , action would work instantly. API_GenAddRecordForm and Richtext is a nice combination with IFV=1 , I will also try it out 

     I'm not aware how "old fashioned web hook" are to be used here ? Any help? 

    Prashant Maheshwari

  • 7.  RE: API button to add new parent record

    Posted 07-18-2022 10:16
    The help text for web hooks is here.  https://help.quickbase.com/user-assistance/configure_a_webhook.html

    I'm not sure I can actually recommend using them in good conscious because there's a lot of syntax and they are more technical so future maintainability will require a developer who is a little more of a Technical Geek type :).  They are also a bit obscure now, so if there was a problem and someone was trying to debug, unless there was clear documentation it may take someone a while to think to look to see if there are any webhooks.

    Here is an example of editing a record from my own cheat notes.

    ENDPOINT: https://mycompany.quickbase.com/db/xxxxxx
    then the next box is the API like API_EditRecord

    ````````````````````````````````````````````````example of API_EditRecord

      <rid>[Record ID#]</rid>
      <field fid="14">[Next Contract Line Item #]</field>

    Mark Shnier (Your Quickbase Coach)