I can't help you with your code page approach, seems too complicated for my style.
I suggest making a button which will update a date time field to the current date time to act as a Submit trigger for a notification. So rather than triggering on "that last piece of data", just have the user click to Submit when they are ready.
If you need the Submit button to also work in Add mode it does get a bit more complicated as normally API_EditRecord needs to act on a Saved record. But we can use a formula Rich Text button to also work in Add mode.
This not tested but might work to save the record and redisplay it to the user regardless of the user is in Add mode or Edit mode.
var text RID = If([Record ID#]>0, ToText([Record ID#]), "%%rid%%");
var text EditRecord = URLRoot() & "db/" & dbid() & "?act=API_EditRecord"
& "&apptoken= xxxxxx" // if you have the need for Application Tokens enabled.
& "&rid=" & ToText($RID)
& "&_fid_99=now"; // set field ID 99 to the current date time to trigger Notification,.
var text DisplayRecordButMissingRID = URLRoot() & "db/" & dbid() & "?a=dr&rid=";
var text URL =
$EditRecord
& "&rdr=" & URLEncode($DisplayRecordButMissingRID) & $RID; // the %%RID%% does not like being URLEncoded.
"<a class='SaveBeforeNavigating' data-replaceRid=true style=\"text-decoration:none; background: #1ba802; border-radius: 5px; color: #ffffff; display: inline-block; padding: 2px 2px 2px 2px; width:200px; text-align: center; text-shadow: none; border: 2px solid #1ba802; font-size: 18px \"href='"
& $URL
& "'>Submit</a>"
------------------------------
Mark Shnier (YQC)
mark.shnier@gmail.com
------------------------------