Discussions

Expand all | Collapse all

Is it possible to customize the file name when exporting a report from a table?

  • 1.  Is it possible to customize the file name when exporting a report from a table?

    Posted 01-04-2018 16:32
    Hi,

    When I export a report in csv format say from a Customers table, the file that gets created has the name Customers-##.csv. 

    I have another application which I need to upload this file onto which requires a specific file name.

    Instead of having to rename the file manually each time once its exported from QB, is there a way to have the file name automatically renamed to a custom file name (for example, from Customers-##.csv to MyCustomers.csv)?

    Thanks for any help you can provide!


  • 2.  RE: Is it possible to customize the file name when exporting a report from a table?

     
    Posted 01-04-2018 16:57
    I dont think you can do it natively, but it is definitely feasible using a workato recipe. In fact if you are using a cloud service it will upload the csv file into the specific destination as well.

    SO essentially you will trigger a webhook using a button that calls a workato recipe. It creates a csv file based on the query and uploads the resulting csv file to your designated location. 


  • 3.  RE: Is it possible to customize the file name when exporting a report from a table?

    Top
    Contributor
    Posted 01-05-2018 18:39
    First of all, you can do this natively and what can't be done natively can be done with script. Second of all you should endeavor to do everything you can within QuickBase before resorting to external services. I am sure Workao is a fine product but a best practice that you should keep at the top of your list st to minimize the number of external services you employ as it just creates more potential points of failure and additional cost.

    You can do this with a plain old native boring formula rich text field. It is painful for me to answer with a native solution and not use script but alas some of you mistakenly think native is easier to use then script.

    In the following formula I am forcing the downloaded file to have a base file name of "myfile" while preserving the original extension of the [file] file attachment field field (pdf, mpeg, etc)

    var Text fileName = Part([file], 1, ".");
    var Text fileExtension = Part([file], 2, ".");
    "<a href='https://haversineconsulting.quickbase.com/up/bnddv44yh/g/r"; & [Record ID#] & "/f6/v0/' download='myfile." & $fileExtension & "'>Download myfile." & $fileExtension & "</a>"

    See screenshot taken after clicking both hyperlinks (note file name in download area):

    ">https://d2r1vs3d9006ap.cloudfront.net/s3_images/1689354/RackMultipart20180105-91358-p7zcz2-screenshot_inline.jpg?1515179244">

    Notes:

    (1) You will have to substitute your dbid and subdomain.

    (2) My formula assumes you only have one versoin of the file attachment field

    (3) You might have to play with the logic a bit to get your desired download behavior in consideration of the specific types of files you will be downloading and the desired name you want to assign.

    (4) BTW, you can download any content whatsoever as a file WITHOUT having a file attachment field.

    (5) This formula uses the download attribute of the <a> element to force the renaming of the file to the value specified. In some cases the MIME type (extension) may be overridden by a server sent header and there may be different behavior in the various browser (I only tested this in Chrome). If you use this formula do everyone a favor and report your success by testing your implementation in the various browser.

    (6) Here is a resource to help you understand using the download attribute:

    https://davidwalsh.name/download-attribute


  • 4.  RE: Is it possible to customize the file name when exporting a report from a table?

    Posted 04-25-2018 18:40
    Hey Dan, was hoping you could help me get to the next level with this. If the file you are downloading is not an uploaded file, but the result of a query, how would you indicate that in your formula? 

    Here is what I have so far, which is in a Formula URL Field, that pulls the correct query on an ask the user report. The report has the format set to CSV - so it downloads automatically.
    URLRoot()  & "db/" & [_DBID_LINE_ITEMS] & "?a=q&qid=19&nv=1&v0=" & [Record ID#]

    I'd like to incorporate your updating of the naming convention on that queried report, but not sure how to string it together. Any advise on that? thanks so much!


  • 5.  RE: Is it possible to customize the file name when exporting a report from a table?

    Top
    Contributor
    Posted 04-25-2018 19:10
    I have been busy with other work and family matters and have not answered many questions for the last few weeks. Over the next few days I am going to pick about a dozen questions which either have been unanswered or quite frankly have bad answers. I put your question on my to do list.


  • 6.  RE: Is it possible to customize the file name when exporting a report from a table?

    Top
    Contributor
    Posted 04-27-2018 15:02
    The script in this Pastie shows you one way of forcing a name for the downloading of a Report as CSV:

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

    Below is a screenshot of manually running the script from the console. Note that the downloaded file has the name "Formulas.csv" instead of the default name "Formula_Functions_Reference.csv". When using this solution it is probably best to date and time stamp the file name so that the file will automatically have a unique name. This is because the browser will add a suffix to the file name if you have already downloaded the file.



    If you need help with this solution feel free to contact me off-world using the information in my profile:

    https://getsatisfaction.com/people/dandiebolt/


  • 7.  RE: Is it possible to customize the file name when exporting a report from a table?

    Posted 11-28-2018 13:35
    Dan, unfortunately your solution above doesn't seem to work properly with .jpg files for some reason. I'm not sure if Quickbase handles photo files differently or what...

    I tried it the original way you have above, which resulted in an unreadable .jpg file named myfile.jpg.

    I also tried this:

    var Text fileExtension = Part([Photo], 2, ".");

    "<a href='" & URLRoot() & "up/" & Dbid() & "/a/r" & [Record ID#] & "/e6/v0/' download='myfile." & $fileExtension & "'>Download Photo</a>"

    This resulted in a download of the original file (not renamed). I'm using Chrome.


  • 8.  RE: Is it possible to customize the file name when exporting a report from a table?

    Top
    Contributor
    Posted 11-28-2018 14:26
    Use this version and then spontaneously break into a celebratory cubicle dance:
    function download(url, fileName) {
      fetch(url, {
          credentials: "include"
        }).then(response => response.blob())
        .then(blob => {
          var link = document.createElement("a");
          link.href = window.URL.createObjectURL(blob);
          link.download = fileName;
          link.click();
        })
    }
    var url = "https://haversineconsulting.quickbase.com/up/bm3ttgwp6/g/rb/eg/va/rythm.mp3"">https://haversineconsulting.quickbase.com/up/bm3ttgwp6/g/rb/eg/va/rythm.mp3"">https://haversineconsulting.quickbase.com/up/bm3ttgwp6/g/rb/eg/va/rythm.mp3";
    var fileName = "Kryptonite.mp3";
    download(url, fileName);

    You can test this by navigating to the Pastie Database and pasting the code into the console.

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




  • 9.  RE: Is it possible to customize the file name when exporting a report from a table?

    Top
    Contributor
    Posted 11-28-2018 14:44
    BTW, the reason the download attribute does not work is because QuickBase sets the Content-Disposition header which has a higher priority in naming the file.




  • 10.  RE: Is it possible to customize the file name when exporting a report from a table?

    Posted 11-28-2018 15:05
    Thank you, but I'm trying to use a Rich Text Formula field to create a download link, as you had indicated in your first response to the original question, so I don't think I can incorporate javascript in this case. Is there any way to rename a .jpg file for download using a Rich Text Formula field?


  • 11.  RE: Is it possible to customize the file name when exporting a report from a table?

    Posted 11-28-2018 15:42
    The following solution works in a URL Formula Field. Thanks for your help, Dan! Very much appreciated!

    var Text url = URLRoot() & "up/" & Dbid() & "/a/r" & [Record ID#] & "/e6/v0/";
    var Text fileName = "Photo.jpg";

    "javascript:fetch('" & $url & "',{credentials: 'include'}).then(response => response.blob()).then(blob => {var link = document.createElement('a'); link.href = window.URL.createObjectURL(blob); link.download = '" & $fileName & "'; link.click();})"


  • 12.  RE: Is it possible to customize the file name when exporting a report from a table?

    Top
    Contributor
    Posted 11-28-2018 15:59
    So simple:
    "<a href=# class='Vibrant Success' onclick=\"fetch('" & [url] & "',{credentials:'include'}).then(response=>response.blob()).then(blob=>{var link= document.createElement('a');link.href=window.URL.createObjectURL(blob);link.download='Kryptonite.mp3';link.click();})\">Download</a>"
    This is a Rich Text Formula field that uses the field [url] and a hard-coded file name of Kryptonite.mp3

    It looks like this on my test page:




  • 13.  RE: Is it possible to customize the file name when exporting a report from a table?

    Top
    Contributor
    Posted 11-28-2018 16:10
    I rarely use the javascript protocol in a URL formula field because you can't style it as a button. If you are careful you can modify my formula to make the literal string "Kryptonite.mp3" a parameter in the same way you did with the formula variable Text fileName.


  • 14.  RE: Is it possible to customize the file name when exporting a report from a table?

    Posted 11-28-2018 16:13
    Ah, that makes sense. Thanks again!


  • 15.  RE: Is it possible to customize the file name when exporting a report from a table?

    Top
    Contributor
    Posted 11-28-2018 16:34
    There are a lot of documentation steps that I have to go through that you never see so I can locate these solutions later.

    Pastie Database (Formula)
    https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=692