How Can I Run Scripts From Buttons On The Application Dashboard?

  • 39
  • 1
  • Question
  • Updated 12 months ago
  • Answered

How Can I Run Scripts From Buttons On The Application Dashboard?

Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,064 Points 20k badge 2x thumb

Posted 4 years ago

  • 39
  • 1
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,064 Points 20k badge 2x thumb
When you click on a button in the Button Bar of your dashboard the URL associated with the button will load and take you away from the dashboard. So there isn't a native way to run script from these buttons and stay on the dashboard page. Well that is easy to fix. First here is a demo with two Alert buttons which run corresponding scripts without reloading or navigating away from the dashboard:

No Tables Just Script
https://haversineconsulting.quickbase.com/db/bj44c8h29

alert1.js
https://haversineconsulting.quickbase.com/db/bj44c8h29?a=dbpage&pagename=alert1.js

alert2.js
https://haversineconsulting.quickbase.com/db/bj44c8h29?a=dbpage&pagename=alert2.js

Here is how you set it up:

(1) save your scripts as user defined pages with a .js extension - for example you might have a script named ProcessRecords.js.

(2) in the button bar of the dashboard create buttons for each script and select the URL to your user defined page. If you did nothing more clicking on one of these buttons would display the contents of the JavaScript file as text. But we will do something more in the following steps that will modify the behavior of the buttons to load the script and unload the dashboard page.

(3) Save the following file as a user defined page in include it as a web page widget on your dashboard.

MyIframe.html
https://haversineconsulting.quickbase.com/db/bj44c8h29?a=dbpage&pagename=MyIframe.html

(4) Edit the file MyIframe.html source to specify the names of the script file and the label you would like to display on your buttons (don't make any other changges)

        var buttons = [
          {script: "alert1.js", label: "Alert 1"},
          {script: "alert2.js", label: "Alert 2"}
        ];

(5) Well that is all you have to do. When the MyIframe.html file loads on the dashbaord, it will make modifications to the buttons in the Button Bar and hide the display of the iframe so there is no evidence of the crime.

Now you can run all your administrative scripts from your application dashboard off of the Button Bar.

Pastie Database
https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=425
Photo of Kp

Kp

  • 14 Points
this is great, but does it work on mobile?
Photo of Ken Casser

Ken Casser

  • 702 Points 500 badge 2x thumb
Hi Dan, Now I'm on to this but I'm not totally understanding it.  In Step 3, I think you want me to click on your link, https://haversineconsulting.quickbase.com/db/bj44c8h29?a=dbpage&pagename=MyIframe.html and copy that to a new code page named "MyIframe.html", but either the link isn't working or I'm not understanding the process.  Is there a new link?  Thank you!
Photo of Ken Casser

Ken Casser

  • 702 Points 500 badge 2x thumb
OK, I got the MyIfile.html file, copied it to a code page named MyIfile.html and created a webpage on my dashboard.  I created a button with the URL for my xxxx.js page, but when I load the homepage, the web widget just displays a webpage with the MyIfile.html code.  I'll keep after it, but if you know what I'm doing wrong, please chime in.  Thank you!
Photo of Ken Casser

Ken Casser

  • 702 Points 500 badge 2x thumb
Dang - I got it!!!  Thank you!