Forum Discussion

BillBurrrell's avatar
BillBurrrell
Qrew Member
4 years ago

Download Report and Mark entries as downloaded

So I'm trying to setup a system that gets me a file of a set of entries from one table. I need it as a .xlsx, but I can convert the file from a .csv easy enough. I also need to mark all entries that are exported as exported. I'm hoping to get do everything from a single click, up to the export anyway (the file conversion can be done manually).

So I'm currently looking at using a URL button to launch a code page. I'm using a report to pass the fields/data to be used and exported. I've managed to get the URL button to work. But I'm struggling with setting up the code page, mostly since I don't have much experience with Javascript. This has been enough to get the button to function for the download, but I'm having a hard time figuring out the next steps. I've got this far mostly by taking a large number of examples from others on here and playing around a bunch.

I'm assuming I'll have to use the DoQueryCount and EditRecord APIs in a loop of sorts to update each record. I've got a simple checkbox, [Exported], for tracking the files that have been exported. Any advice/suggestions would be appreciated.

//URL button code

var text GetReport = "?a=q&qid=10";
var text DownloadReport = "&opts=csv";

URLRoot() & "db/" & AppID() & "?a=dbpage&pageid=42" & // code page
"&url=" & URLEncode(URLRoot() & "db/" & Dbid() & $GetReport) & //passed to code page for marking records downloaded
"&rdrurl=" & URLEncode(URLRoot() & "db/" & Dbid() & $GetReport & $DownloadReport)//passed for final redirect
//Code Page

<!DOCTYPE html>
<html>
<head>
<script>
var urlParams = new URLSearchParams(window.location.search);
var url = urlParams.get('url');
var rdrurl = urlParams.get('rdrurl');

window.open(url,'Print');
window.location.href = rdrurl;
</script>
</head>
</html>


------------------------------
Bill Burrrell
------------------------------
  • AustinK's avatar
    AustinK
    Qrew Commander
    This is a really tough one to help with because while someone could post some basic code to get you there it would not be something I would want to run without improving the code and adding several checks within it to make sure things are working properly and the data is what you expect it to be each time. There are a lot of "best practices" that would not be in there if this just got slapped together.

    I can say that anytime I need to use JavaScript with a code page I almost always use a library as I found it makes things easier. The really nice thing about this site I am going to link is it offers examples for every api call it handles. 

    https://tflanagan.github.io/quickbase.dev//#quickbase

    As far as what to look into I think you should only need to do a DoQuery to start off. You can either create your own query there or simply have a report ready to go that the api can call. You will need to navigate some JSON to get it done though as that is what this returns.