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
------------------------------