Discussions

Expand all | Collapse all

Javascript in Formula URL Help

  • 1.  Javascript in Formula URL Help

    Posted 10-04-2018 02:11
    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?">https://hooks.zapier.com/hooks/catch/3675846/l9mgrj/silent?GTIN="">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


  • 2.  RE: Javascript in Formula URL Help

    Posted 10-04-2018 02:18
    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) 


  • 3.  RE: Javascript in Formula URL Help

    Posted 10-04-2018 15:18
    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="">https://hooks.zapier.com/hooks/catch/3675846/l9mgrj/silent?GTIN="">https://hooks.zapier.com/hooks/catch/XXXXXXXXXXX="

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


  • 4.  RE: Javascript in Formula URL Help

    Posted 10-04-2018 02:23
    As for the popup box, there are so many ways to do this, for the sake of expedience have a look at Dans pastie in the below link, his pastie collection is a good starting point in extreme cases or a good resource to save time in general as you are starting your Javascript adventure in quickbase.

    https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=7&rl=w2v



  • 5.  RE: Javascript in Formula URL Help

     
    Posted 10-04-2018 03:20
    $.get is shorthand for a jquery Ajax (Asynchronous JavaScript and XML) call.  The asynchronous nature of this allows for exactly what you are looking to do in a non-blocking way.

    You just need hit up a .then() or similar after your API call.

    Here are some docs:

    https://api.jquery.com/jquery.get/
    More stuff: https://api.jquery.com/category/ajax/

    Hope this helps,

    ~Rob


  • 6.  RE: Javascript in Formula URL Help



  • 7.  RE: Javascript in Formula URL Help

    Posted 10-04-2018 07:02
    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);"
    "});" 


  • 8.  RE: Javascript in Formula URL Help



  • 9.  RE: Javascript in Formula URL Help

    Posted 10 days ago
    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
    ------------------------------



  • 10.  RE: Javascript in Formula URL Help

    Posted 10 days ago
    In the Quick Base formula language when you want to use an intermediate calculation for ease of writing a formula you can create what is called a formula variable.  Here is some help on that.

    https://help.quickbase.com/user-assistance/formula_variables.html

    ------------------------------
    Mark Shnier (YQC)
    Quick Base Solution Provider
    Your Quick Base Coach
    http://QuickBaseCoach.com
    mark.shnier@gmail.com
    ------------------------------