Forum Discussion

AngelRodriguez's avatar
AngelRodriguez
Qrew Assistant Captain
2 years ago

API_AddRecord Formula URL Button Creating Duplicates

I'm using the API_AddRecord API on a formula URL button to submit a form as opposed to using the standard "Save & close" button.  I'm doing this in order to redirect the user, to a "document saved" type code page. 

 

Within the API_AddRecord code, I'm simply pushing entered field values into existing fields.  The Patient Date of Birth (fid_8), Sender Name (fid_10), Sender Phone Number (fid_11), Sender Email Address (fid_12), Patient Full Name (fid_20), and Uploaded Document (fid_16) are all required at the field level.   There's a redirect that redirects to a code page within the app,  a simple html page displaying "Your document has been successfully submitted.", then a setTimeout function that redirects back into the Quickbase app onto a blank form (same as the original form submit).  That being said, once the user adds fields values and saves, they are redirected to the code page, then directed back into the app onto the form.  For whatever reason, this creates two records.  It's odd because not all the data is saved on the second record save.  For example the document (required), the sender and organization phone extensions and sometimes the Document Types multi-select field values are not saved on the duplicate.  I'm not sure that the last part is too important, but I figured I'd mention that because it's something I noticed each time this happened.

 

In order to rule out the field level requirements and code page being the issue, I even removed the field level requirements on all fields and the redirect to the code page where instead I'm just redirecting back to the saved record (using the below testRedirect URL), but the submission via the API button is still creating a duplicate each time.  I'm wondering if anyone else has experienced any bugs using this same API (API_AddRecord)?  Or if you notice anything in my formula that may cause this duplicate submission.

 

Here's the formula URL button code:

 

var text tableName = [_DBID_SUBMITTED_DOCUMENTS];

var text appToken = "&apptoken=XXXXXX";

var text redirectURL = "&rdr=" & URLEncode("https://XXXXXX.quickbase.com/db/XXXXXX?a=dbpage&pageID=2");

//var text testRedirect = "&rdr=" & URLEncode(URLRoot() & "db/" & Dbid() & "?a=dr&rid=" & [Record ID#]);

 

var text createNewSubmission =

    URLRoot() & "db/" & $tableName

    & "?a=API_AddRecord"

    & "&_fid_8=" & [Patient Date of Birth]

    & "&_fid_9=" & [Clinical Organization]

    & "&_fid_10=" & [Sender Name]

    & "&_fid_11=" & [Sender Phone Number]

    & "&_fid_12=" & [Sender Email Address]

    & "&_fid_14=" &

    & "&_fid_15=" & [Attention]

    & If ([Document]<> null, "&_fid_16=" & URLEncode([Document]))

    & "&_fid_17=" & [Document Types or Purpose]

    & "&_fid_19=" & [Organization Phone Number]

    & "&_fid_20=" & [Patient Full Name]

    & $appToken

    & $redirectURL;

    //& $testRedirect;

 

$createNewSubmission

Here's the first submission. redirects to code-page


And the second submission - redirects back to Quickbase, no code-page

Report with both record submissions.  Red is the original submission and green is the duplicate.



------------------------------
AR
------------------------------

7 Replies

  • Hello, when I have done this I do it in a code page different from the forms that quickbase can offer, I am not very sure, but it occurs to me that the quickbase form has formSubmit configuration, by including an additional submit it is possible that they are being done 2 see submit and this will "duplicate" the record. It's a crazy idea for a crazy problem.

    Marcelo Benavides Torres


  •  I think that that you way overcomplicated this.  The button should just be
    "https://XXXXXX.quickbase.com/db/XXXXXX?a=dbpage&pageID=2"
    or better yet.

    Urlroot() & "db/" & AppID() & "?a=dbpage&pageID=2"

    ie, like that all for the whole button!

    Once you dirty the input form when you go to navigate away from the record (to send the user to the code page) it will auto save without all that code. 

    I think what's actually happening now as you were sitting on the input form and when you push the button it immediately adds a record and then because the form has been dirtied before it navigates the way it saves the record. So now you have a duplicate of the record.   



    ------------------------------
    Mark Shnier (Your Quickbase Coach)
    mark.shnier@gmail.com
    ------------------------------
    • AngelRodriguez's avatar
      AngelRodriguez
      Qrew Assistant Captain

      Mark, I replaced the formula URL button's formula with

      Urlroot() & "db/" & AppID() & "?a=dbpage&pageID=2"

      Replacing AppID() with my actual app ID in quotes, and I'm still getting the same exact behavior.  Although there's no redirect to the code page, it's just redirecting back to an empty form.  But each save still creates a duplicate.  Seems like a bug, but it's hard to tell because I can't debug what's actually happening.

      Thanks!



      ------------------------------
      AR
      ------------------------------

      • MarkShnier__You's avatar
        MarkShnier__You
        Icon for Qrew Legend rankQrew Legend

        I'm now confused.  Can you post your complete current formula.



        ------------------------------
        Mark Shnier (Your Quickbase Coach)
        mark.shnier@gmail.com
        ------------------------------