Creating a csv file with the new getAsText

In rc7 under Database Manager/JSDataset, I see the sample for the new getAsText:

//assuming the variable dataset contains a dataset, you can create csv or tab delimited results
var csv = dataset.getAsText(',','\n','"',true)
var tab = dataset.getAsText('\t','\n','"',true)

How do I make the csv variable contain all columns and rows of a table?

Hi Westy,

try this:

var query = 'SELECT * FROM sometablename';
var maxReturnedRows = 10000;
// replace sometablename with the name of your table and make sure
// maxReturnedRows is greater than the number of rows.
var dataset = databaseManager.getDataSetByQuery(currentcontroller.getServerName(), query, null, maxReturnedRows);

Thank you very much!

It seems like getAsText is a very big new feature of Servoy!

I just tried it with

var query = 'SELECT * FROM contacts'; 
var maxReturnedRows = 10000; 
// replace sometablename with the name of your table and make sure 
// maxReturnedRows is greater than the number of rows. 
var dataset = databaseManager.getDataSetByQuery(currentcontroller.getServerName(), query, null, maxReturnedRows); 
//assuming the variable dataset contains a dataset, you can create csv or tab delimited results
var csv = dataset.getAsText(',','\n','"',true)
//var tab = dataset.getAsText('\t','\n','"',true)
//Write textual file
var fileNameSuggestion = 'myspecialexport.csv'
var textData = csv
var success = plugins.file.writeTXTFile(fileNameSuggestion,textData);

to export all records from my contacts file and it worked perfectly (placing the myspecialexport.csv file in the Servoy folder).

I will test this some more, but it now seems like we can have a multi-company solution using the addTableFilterParam and export the filtered records for one company from all tables with a single method.