Forum Discussion

MuraliGangineni's avatar
MuraliGangineni
Qrew Cadet
7 years ago

Download Excel CSV file directly to the local system on the click of a button on the Table Report

I want an Action button on the current page table report where clicking on that button will directly downloads the Excel CSV File to my Local System. Is it possible to have a button like that in QuickBase and if So, How to achieve this in QuickBase ?

(Note: I don't want to use QuickBase IMPORT/EXPORT option to download the file)
  • Yes it is possible in a variety of ways. Here is one way that uses a technique to jam the relevant JavaScript into an onclick handler of an <a> element synthesized using a Rich Text Formula Field.
    "<a href=# class='Vibrant Success' onclick='
    function download(filename, content) {
      var blob = new Blob([content]);
      var a = document.createElement('a');
      a.href = window.URL.createObjectURL(blob); 
      a.download = filename;
      a.style.display = 'none';
      document.body.appendChild(a);
      a.click();
    }

    var dbidTable= 'bgcwm2m4g';
    var qid = '1';
    var output = 'output.csv';
    var url = '${dbidTable}?a=q&qid=${qid}&opts=csv';
    $.get(url, function(csv) {
      download('${output}', csv);
    });
    '>Download</a>"

    Here is a screenshot of the Formula Definition  being entered:



    This is one big text string with hard-coded values for dbidTableqid and output. You would need to changes these values to suit your needs or modify the formula to pass in field values from the record.

    There are three types of quotes used in this formula and you need to take great care not to mess any of them up:

    (1) Double quotes (ie ") are used at the beginning and end a double quotes are used in the formula language to delineate text strings.

    (2) Single quotes (ie ') are used to deliniate the start and end of the onclick attribute of the <a> element.

    (3) Backtick quotes (ie ') are used in the body of the JavaScript code where normally you might use single or double quotes and also where string interpolation is being performed (their real use).

    Pastie Database
    https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=700

    I just noticed that this is the 700th record entered into the Pastie Database so I am going to celebrate with Kool & The Gang!


    • JasonJohnson2's avatar
      JasonJohnson2
      Qrew Cadet
      This is almost perfect for my need. I want to from a form in one table print a report from another table but to add filtering so that it is only records related to that record being saved.
      I attempted to do this by changing my report to add add an ask user filter then added this into the script
      var srt = '&nv=1&v0=';
      var wtr = '[Record ID#]';
      Then I changed the script on the URL to 
      var url = '${dbidTable}?a=q&qid=${qid}&${srt}&${wtr}&opts=csv';

      I get an export but it is 4900+ lines of code, definitely not the report.
  • QuickBase refuses to make it easy to introduce JavaScript into the product so we will just take over the formula language with script.

    I came up with a snappy name that will make this technique memorable. Henceforth this technique will be called:
    Three Quotes And A Script Technique = 3Q&S
  • Hi Murali, 

    Currently a report can be saved as a CSV by using the option to Import/Export or 'Save as Spreadsheet' under the More dropdown on a table report. 'Save as Spreadsheet' will jump right to creating a CSV to download. Either will allow a user to pull the data from a Quick Base table into a CSV. Out of curiosity is there something about the two options under the More dropdown that make them undesirable for your use?_
    • _anomDiebolt_'s avatar
      _anomDiebolt_
      Qrew Elite
      He wants a friction-less single button way to download and doesn't want to navigate through the GUI.

      My technique is very general but you can make it even simpler by just adding &opts=csv to the end of the report URL. This example will immediately download the CSV for the Formula Function report

      Download Formula Functions Report as CSV:
      https://login.quickbase.com/db/6ewwzuuj?a=q&qid=6&opts=csv

      QuickBase immediately downloads the report as CSV because of the way the content-disposition header is set in the response. What you don't get with this simpler approach is (1) the ability to name the CSV file or (2) potentially modify the CSV in some fashion prior to download.

      The technique I have supplied is extremely general. You can download your QuickBase data in any text format you want with the download(filename, content) function with a single button click.


    • EvanMartinez's avatar
      EvanMartinez
      Quickbase Staff
      Thanks Dan, that is what I am curious of. I just wanted to confirm if it is the location of the option or if it is something about how the options in the dropdown work so I can pass that feedback along. 
    • _anomDiebolt_'s avatar
      _anomDiebolt_
      Qrew Elite
      This is the feedback you should pass along:

      QuickBase staff is collectively obsessed with use case analysis and hard-coding features that have limited ability to be further customized by the end user. Users want general capabilities that can be customize to their individual snowflake needs no matter how cosmetic or complex.

      But user's individual requests often go unaddressed because the feature is viewed as non-critical and never crosses the popularity threshold so that marketing and product managers commit to developing the feature. It is all about the long tail today.

      Every GUI ease of use feature you develop should have an analog that can accomplish the same thing through an API and script automation. You need functional parity between the "clicks not code" and "code not clicks" memes. Without greater support for APIs and script you are locking your users out of the using the cornucopia of features that are coming through browser innovations. QuickBase should view all the innovations that are jammed into browsers today as economic externalizes that someone else paid for developing.