Redirect Preventing Script From Running

  • 0
  • 1
  • Question
  • Updated 4 years ago
  • Answered
I have a custom .htm page sitting in my app that does some calcs via jscript then calls API_EditRecord to update some fields.

I then created a formula-HTML button that invokes the code page.  Everything runs fine, until I add a redirect parameter to the HTML button.

Is it possible that the redirect occurs before the script is finished executing?

Here's the code in the formula-html button calling my script without the redirect (works fine):

"https://xxx.quickbase.com/db/mytableid?a=dbpage&pageID=4"

Here is the same formula but with a redirect (which works but my jscript doesn't execute):

"https://xxx.quickbase.com/db/mytableid?a=dbpage&pageID=4&rdr="& URLEncode(URLRoot() & "db/" & Dbid() & "?a=er&rid=" & [Record ID#])

Any help is appreciated as always.  Thanks
Photo of Brian

Brian

  • 0 Points

Posted 4 years ago

  • 0
  • 1
Photo of Tom_M

Tom_M, Champion

  • 30 Points
I think you should use window.location.replace(YourURLHere) as the last step in the script in your custom page instead of using the rdr parameter in a Formula HTML button. By placing the redirect into your script as the last step, you can ensure that the script will run prior to the redirect as well as providing you with a chance to perform any error checking on the steps in your script (e.g. calculations, determine success of API_EditRecord call, etc.) to issue any necessary alerts prior to redirecting to the new page. Hope this helps.
Photo of Brian

Brian

  • 0 Points
Thanks, Tom.  I've already tried this approach with no success.  When I try this, the exact same thing happens.  Script runs fine without window.location.replace(), but as soon as I add that as the last line in my script, the script does not run.  All different redirect methods seems to be causing this.

Almost seems as if my problem is somewhere else...
Photo of Tom_M

Tom_M, Champion

  • 30 Points
One possible problem could be that by default, the jQuery ajax method is set to perform the requests asynchronously. So as the script runs, it is not waiting for all of the calculations and/or the API_EditRecord call contained in your code to finish before executing the line containing the redirect code. If this is the case, you could try using jQuery's promises [e.g. $.when().then()] to force the redirect part of the script to wait until your other computations/calls are finished before executing the redirect.