Forum Discussion

ScottPugh's avatar
ScottPugh
Qrew Cadet
6 years ago

Javascript in Formula URL Help

From other posts I was able to put together the following code for a Formula URL button.  This accomplishes the main actions of calling a 3rd party REST API and then reloading the current page.   

var text URL= "https://hooks.zapier.com/hooks/catch/XXXXXXXXXXX?;


"javascript:" &
"$.get('" & 
$URL & 
"',function(){" &
"location.reload(true);" &
"});" 
& "void(0);"

I'd like to know if its possible to do one of two (or both) additional actions

1.  Is it possible to add a delay before the page reloads?
2.  Is it possible to show a pop-up box the user would click on and then reload the page

I basically just need to buy a second or two while the REST API that was called does its thing and then ultimately updates a record back in Quickbase before the page reload occurs

Thanks for the help

9 Replies

  • For the first one is straight forward, below is the timeout function, i use a fat arrow function with no input, and call location.reload(true) after 2 seconds or 2000 milliseconds.

    setTimeout(()=> location.reload(true),2000) 
    • ScottPugh's avatar
      ScottPugh
      Qrew Cadet
      Josh- thanks for the reply.   A small change- if instead of doing a reload of a page I want to redirect the user to a different quickbase page... what would the full syntax be?  currently I have

      var text URL= "https://hooks.zapier.com/hooks/catch/XXXXXXXXXXX="

      "javascript:" &
      "$.get('" & 
      $URL & 
      "',function(){" &
      "setTimeout(()=> location.reload(true),5000)  " &
      "});" 
      & "void(0);"
    • JoshuaTate's avatar
      JoshuaTate
      Qrew Cadet
      there's no need to use .then in this case, the get function in Jquery allows a call back function after completion. Scott has demonstrated the correct use of the call back function in his example. He just needs to use the block per below:
      "javascript:" &
      "$.get('" & 
      $URL & 
      "',function(){" &
      "setTimeout(()=> location.reload(true),2000)  location.reload(true);" &
      & "void(0);"
      "});" 
      • AngelRodriguez's avatar
        AngelRodriguez
        Qrew Assistant Captain
        I'm seeing a lot of this in the forums"var text URL" to declare a JavaScript variable in QuickBase. Is the "text" necessary? It's confusing because we don't declare data types in JavaScript so if I want to declare a variable, can't I just go with "var url = <define variable...>" or "var URL = "<define variable...>"?

        ------------------------------
        Angel Rodriguez
        ------------------------------