publish
plugins.it2be_data.IDCsv info


Servoy Properties Summary
String delimiter
String encoding
Boolean writeHeader


Servoy Methods Summary
Array<Array<Object>> getArray( String, Object )
Array<Array<Object>> getArray( String, Boolean, String )
Array<Array<Object>> getArray( String )
JSDataSet getDataSet( String, Boolean, String )
JSDataSet getDataSet( String )
JSDataSet getDataSet( String, Object )
String write( String, Object, Object, Object )
String write( String, Object )
String write( String, Object, Object )
String write( String, Array<Object>, Object, Boolean, String )
String writeArray( String, Array<Object>, Array<Array<Object>>, Object )
String writeArray( String, Array<Object>, Array<Array<Object>>, Boolean, String )


Servoy Properties Details


delimiter
String  delimiter
Get/Set the delimiter
Returns
String  delimiter String

Supported Clients
SmartClient, WebClient, NGClient


encoding
String  encoding
Get/Set the encoding
Returns
String  encoding String

Supported Clients
SmartClient, WebClient, NGClient


writeHeader
Boolean  writeHeader
Get/Set to write the header to the file.
Returns
Boolean  write boolean

Supported Clients
SmartClient, WebClient, NGClient

Servoy Methods Details


getArray
Array<Array<Object>>  getArray( String, Object )
Read a CSV file and return a 2D Array. The show header property defaults to true.
Parameters
String  filePath  the file path
Object  value  showHeader:boolean or delimiter:String

Returns
Array<Array<Object>>  array Object[][]

Supported Clients
SmartClient, WebClient, NGClient

Sample
// set the name of the file
var file = plugins.file.showFileOpenDialog();

// check that we really selected a file
// if not ignore the rest of the code
if (file) {
var filePath = file.getAbsoluteFile();
var set = null;
var array = null;

// with the show header parameter set to true the first row will will show in the result

// create a dataset from the file
// the show header parameter is set to false by default
// REMARK: a header will always be constructed from the first row
// set = plugins.it2be_data.csv().getDataSet(filePath);

// or retreive it with the delimiter set to a comma
set = plugins.it2be_data.csv().getDataSet(filePath, ",");

// create a two dimensional array from the file
// the show header parameter is set to true by default
array = plugins.it2be_data.csv().getArray(filePath, true);

// when the dataset is NOT empty
if (set.getMaxRowIndex()) {
var message = "";

// output to the debugger to show there is a result
application.output("set.getMaxRowIndex() = " + set.getMaxRowIndex());

// because the set is a 'standard' JSDataSet all the functions and properties
// we can use the Database Manager to retrieve the column count and column names
var columncount = set.getMaxColumnIndex();

// limit the number of columns we show to 5 when columncount > 5
// 5 is an arbitrary value to limit the width of the dialog
columncount = (columncount > 5) ? 5 : columncount;

// loop through the columns
for (var i = 1 ; i <= columncount ; i++) {
// retreive the names
message += set.getColumnName(i) + "::";
}
message += "\n";

// JSDataSet.sort(number, boolean) is also valid
set.sort(1, false);

var rowcount = (set.getMaxRowIndex() > 5) ? 5 : set.getMaxRowIndex();

// loop through the rows of the JSDataSet
// REMARK: the JSDataSet starts counting at 1 instead of 0
for (var i = 1 ; i <= rowcount ; i++) {
// loop through the columns
for (var ii = 1 ; ii <= columncount ; ii++) {
// and retreive the column values
message += set.getValue(i, ii) + "::";
}
message += "\n";
}

// show the result
if (message) {
plugins.dialogs.showInfoDialog("JSDataSet", message);
}
} else {
// output to the debugger to show there is NO result
application.output("JSDataSet = null");
}

// when the array is NOT empty
if (array) {
var message = "";

application.output("array.length = " + array.length);

// because the show header parameter is set to false with a (two dimensional) array
// the first row will NOT show in the array

// limit the column and row count for display purposes
var columncount = (array[0].length > 5) ? 5 : array[0].length;
var rowcount = (array.length > 5) ? 5 : array.length;

// loop through the 3D array
// REMARK: an array starts at index 0
for (var i = 0 ; i < rowcount ; i++) {
for (var ii = 0 ; ii < columncount ; ii++) {
message += array[i][ii] + "::";
}
message += "\n";
}

// show the result
if (message) {
plugins.dialogs.showInfoDialog("Array", message);
}
} else {
// output to the debugger to show there is NO result
application.output("Array = null");
}
}


getArray
Array<Array<Object>>  getArray( String, Boolean, String )
Read a CSV file and return a 2D Array. The show header property defaults to true.
Parameters
String  filePath  the file path
Boolean  showHeader  the showHeader
String  delimiter  the delimiter

Returns
Array<Array<Object>>  array Object[][]

Supported Clients
SmartClient, WebClient, NGClient

Sample
// set the name of the file
var file = plugins.file.showFileOpenDialog();

// check that we really selected a file
// if not ignore the rest of the code
if (file) {
var filePath = file.getAbsoluteFile();
var set = null;
var array = null;

// with the show header parameter set to true the first row will will show in the result

// create a dataset from the file
// the show header parameter is set to false by default
// REMARK: a header will always be constructed from the first row
// set = plugins.it2be_data.csv().getDataSet(filePath);

// or retreive it with the delimiter set to a comma
set = plugins.it2be_data.csv().getDataSet(filePath, ",");

// create a two dimensional array from the file
// the show header parameter is set to true by default
array = plugins.it2be_data.csv().getArray(filePath, true);

// when the dataset is NOT empty
if (set.getMaxRowIndex()) {
var message = "";

// output to the debugger to show there is a result
application.output("set.getMaxRowIndex() = " + set.getMaxRowIndex());

// because the set is a 'standard' JSDataSet all the functions and properties
// we can use the Database Manager to retrieve the column count and column names
var columncount = set.getMaxColumnIndex();

// limit the number of columns we show to 5 when columncount > 5
// 5 is an arbitrary value to limit the width of the dialog
columncount = (columncount > 5) ? 5 : columncount;

// loop through the columns
for (var i = 1 ; i <= columncount ; i++) {
// retreive the names
message += set.getColumnName(i) + "::";
}
message += "\n";

// JSDataSet.sort(number, boolean) is also valid
set.sort(1, false);

var rowcount = (set.getMaxRowIndex() > 5) ? 5 : set.getMaxRowIndex();

// loop through the rows of the JSDataSet
// REMARK: the JSDataSet starts counting at 1 instead of 0
for (var i = 1 ; i <= rowcount ; i++) {
// loop through the columns
for (var ii = 1 ; ii <= columncount ; ii++) {
// and retreive the column values
message += set.getValue(i, ii) + "::";
}
message += "\n";
}

// show the result
if (message) {
plugins.dialogs.showInfoDialog("JSDataSet", message);
}
} else {
// output to the debugger to show there is NO result
application.output("JSDataSet = null");
}

// when the array is NOT empty
if (array) {
var message = "";

application.output("array.length = " + array.length);

// because the show header parameter is set to false with a (two dimensional) array
// the first row will NOT show in the array

// limit the column and row count for display purposes
var columncount = (array[0].length > 5) ? 5 : array[0].length;
var rowcount = (array.length > 5) ? 5 : array.length;

// loop through the 3D array
// REMARK: an array starts at index 0
for (var i = 0 ; i < rowcount ; i++) {
for (var ii = 0 ; ii < columncount ; ii++) {
message += array[i][ii] + "::";
}
message += "\n";
}

// show the result
if (message) {
plugins.dialogs.showInfoDialog("Array", message);
}
} else {
// output to the debugger to show there is NO result
application.output("Array = null");
}
}


getArray
Array<Array<Object>>  getArray( String )
Read a CSV file and return a 2D Array. The show header property defaults to true.
Parameters
String  filePath  the file path

Returns
Array<Array<Object>>  array Object[][]

Supported Clients
SmartClient, WebClient, NGClient

Sample
// set the name of the file
var file = plugins.file.showFileOpenDialog();

// check that we really selected a file
// if not ignore the rest of the code
if (file) {
var filePath = file.getAbsoluteFile();
var set = null;
var array = null;

// with the show header parameter set to true the first row will will show in the result

// create a dataset from the file
// the show header parameter is set to false by default
// REMARK: a header will always be constructed from the first row
// set = plugins.it2be_data.csv().getDataSet(filePath);

// or retreive it with the delimiter set to a comma
set = plugins.it2be_data.csv().getDataSet(filePath, ",");

// create a two dimensional array from the file
// the show header parameter is set to true by default
array = plugins.it2be_data.csv().getArray(filePath, true);

// when the dataset is NOT empty
if (set.getMaxRowIndex()) {
var message = "";

// output to the debugger to show there is a result
application.output("set.getMaxRowIndex() = " + set.getMaxRowIndex());

// because the set is a 'standard' JSDataSet all the functions and properties
// we can use the Database Manager to retrieve the column count and column names
var columncount = set.getMaxColumnIndex();

// limit the number of columns we show to 5 when columncount > 5
// 5 is an arbitrary value to limit the width of the dialog
columncount = (columncount > 5) ? 5 : columncount;

// loop through the columns
for (var i = 1 ; i <= columncount ; i++) {
// retreive the names
message += set.getColumnName(i) + "::";
}
message += "\n";

// JSDataSet.sort(number, boolean) is also valid
set.sort(1, false);

var rowcount = (set.getMaxRowIndex() > 5) ? 5 : set.getMaxRowIndex();

// loop through the rows of the JSDataSet
// REMARK: the JSDataSet starts counting at 1 instead of 0
for (var i = 1 ; i <= rowcount ; i++) {
// loop through the columns
for (var ii = 1 ; ii <= columncount ; ii++) {
// and retreive the column values
message += set.getValue(i, ii) + "::";
}
message += "\n";
}

// show the result
if (message) {
plugins.dialogs.showInfoDialog("JSDataSet", message);
}
} else {
// output to the debugger to show there is NO result
application.output("JSDataSet = null");
}

// when the array is NOT empty
if (array) {
var message = "";

application.output("array.length = " + array.length);

// because the show header parameter is set to false with a (two dimensional) array
// the first row will NOT show in the array

// limit the column and row count for display purposes
var columncount = (array[0].length > 5) ? 5 : array[0].length;
var rowcount = (array.length > 5) ? 5 : array.length;

// loop through the 3D array
// REMARK: an array starts at index 0
for (var i = 0 ; i < rowcount ; i++) {
for (var ii = 0 ; ii < columncount ; ii++) {
message += array[i][ii] + "::";
}
message += "\n";
}

// show the result
if (message) {
plugins.dialogs.showInfoDialog("Array", message);
}
} else {
// output to the debugger to show there is NO result
application.output("Array = null");
}
}


getDataSet
JSDataSet  getDataSet( String, Boolean, String )
Read the file and return a JSDataSet.
Parameters
String  filePath  the file path
Boolean  showHeader  the show header
String  delimiter  the delimiter

Returns
JSDataSet  JSDataSet

Supported Clients
SmartClient, WebClient, NGClient

Sample
// set the name of the file
var file = plugins.file.showFileOpenDialog();

// check that we really selected a file
// if not ignore the rest of the code
if (file) {
var filePath = file.getAbsoluteFile();
var set = null;
var array = null;

// with the show header parameter set to true the first row will will show in the result

// create a dataset from the file
// the show header parameter is set to false by default
// REMARK: a header will always be constructed from the first row
// set = plugins.it2be_data.csv().getDataSet(filePath);

// or retreive it with the delimiter set to a comma
set = plugins.it2be_data.csv().getDataSet(filePath, ",");

// create a two dimensional array from the file
// the show header parameter is set to true by default
array = plugins.it2be_data.csv().getArray(filePath, true);

// when the dataset is NOT empty
if (set.getMaxRowIndex()) {
var message = "";

// output to the debugger to show there is a result
application.output("set.getMaxRowIndex() = " + set.getMaxRowIndex());

// because the set is a 'standard' JSDataSet all the functions and properties
// we can use the Database Manager to retrieve the column count and column names
var columncount = set.getMaxColumnIndex();

// limit the number of columns we show to 5 when columncount > 5
// 5 is an arbitrary value to limit the width of the dialog
columncount = (columncount > 5) ? 5 : columncount;

// loop through the columns
for (var i = 1 ; i <= columncount ; i++) {
// retreive the names
message += set.getColumnName(i) + "::";
}
message += "\n";

// JSDataSet.sort(number, boolean) is also valid
set.sort(1, false);

var rowcount = (set.getMaxRowIndex() > 5) ? 5 : set.getMaxRowIndex();

// loop through the rows of the JSDataSet
// REMARK: the JSDataSet starts counting at 1 instead of 0
for (var i = 1 ; i <= rowcount ; i++) {
// loop through the columns
for (var ii = 1 ; ii <= columncount ; ii++) {
// and retreive the column values
message += set.getValue(i, ii) + "::";
}
message += "\n";
}

// show the result
if (message) {
plugins.dialogs.showInfoDialog("JSDataSet", message);
}
} else {
// output to the debugger to show there is NO result
application.output("JSDataSet = null");
}

// when the array is NOT empty
if (array) {
var message = "";

application.output("array.length = " + array.length);

// because the show header parameter is set to false with a (two dimensional) array
// the first row will NOT show in the array

// limit the column and row count for display purposes
var columncount = (array[0].length > 5) ? 5 : array[0].length;
var rowcount = (array.length > 5) ? 5 : array.length;

// loop through the 3D array
// REMARK: an array starts at index 0
for (var i = 0 ; i < rowcount ; i++) {
for (var ii = 0 ; ii < columncount ; ii++) {
message += array[i][ii] + "::";
}
message += "\n";
}

// show the result
if (message) {
plugins.dialogs.showInfoDialog("Array", message);
}
} else {
// output to the debugger to show there is NO result
application.output("Array = null");
}
}


getDataSet
JSDataSet  getDataSet( String )
Read a CSV file and return a JSDataSet. The show header parameter defaults to false.
Parameters
String  filePath  the file path

Returns
JSDataSet  dataset JSDataSet

Supported Clients
SmartClient, WebClient, NGClient

Sample
// set the name of the file
var file = plugins.file.showFileOpenDialog();

// check that we really selected a file
// if not ignore the rest of the code
if (file) {
var filePath = file.getAbsoluteFile();
var set = null;
var array = null;

// with the show header parameter set to true the first row will will show in the result

// create a dataset from the file
// the show header parameter is set to false by default
// REMARK: a header will always be constructed from the first row
// set = plugins.it2be_data.csv().getDataSet(filePath);

// or retreive it with the delimiter set to a comma
set = plugins.it2be_data.csv().getDataSet(filePath, ",");

// create a two dimensional array from the file
// the show header parameter is set to true by default
array = plugins.it2be_data.csv().getArray(filePath, true);

// when the dataset is NOT empty
if (set.getMaxRowIndex()) {
var message = "";

// output to the debugger to show there is a result
application.output("set.getMaxRowIndex() = " + set.getMaxRowIndex());

// because the set is a 'standard' JSDataSet all the functions and properties
// we can use the Database Manager to retrieve the column count and column names
var columncount = set.getMaxColumnIndex();

// limit the number of columns we show to 5 when columncount > 5
// 5 is an arbitrary value to limit the width of the dialog
columncount = (columncount > 5) ? 5 : columncount;

// loop through the columns
for (var i = 1 ; i <= columncount ; i++) {
// retreive the names
message += set.getColumnName(i) + "::";
}
message += "\n";

// JSDataSet.sort(number, boolean) is also valid
set.sort(1, false);

var rowcount = (set.getMaxRowIndex() > 5) ? 5 : set.getMaxRowIndex();

// loop through the rows of the JSDataSet
// REMARK: the JSDataSet starts counting at 1 instead of 0
for (var i = 1 ; i <= rowcount ; i++) {
// loop through the columns
for (var ii = 1 ; ii <= columncount ; ii++) {
// and retreive the column values
message += set.getValue(i, ii) + "::";
}
message += "\n";
}

// show the result
if (message) {
plugins.dialogs.showInfoDialog("JSDataSet", message);
}
} else {
// output to the debugger to show there is NO result
application.output("JSDataSet = null");
}

// when the array is NOT empty
if (array) {
var message = "";

application.output("array.length = " + array.length);

// because the show header parameter is set to false with a (two dimensional) array
// the first row will NOT show in the array

// limit the column and row count for display purposes
var columncount = (array[0].length > 5) ? 5 : array[0].length;
var rowcount = (array.length > 5) ? 5 : array.length;

// loop through the 3D array
// REMARK: an array starts at index 0
for (var i = 0 ; i < rowcount ; i++) {
for (var ii = 0 ; ii < columncount ; ii++) {
message += array[i][ii] + "::";
}
message += "\n";
}

// show the result
if (message) {
plugins.dialogs.showInfoDialog("Array", message);
}
} else {
// output to the debugger to show there is NO result
application.output("Array = null");
}
}


getDataSet
JSDataSet  getDataSet( String, Object )
Read the file and return a JSDataSet. The show header parameter defaults to false.
Parameters
String  filePath  the file path
Object  value  showHeader:boolean or delimiter:String

Returns
JSDataSet  dataset JSDataSet

Supported Clients
SmartClient, WebClient, NGClient

Sample
// set the name of the file
var file = plugins.file.showFileOpenDialog();

// check that we really selected a file
// if not ignore the rest of the code
if (file) {
var filePath = file.getAbsoluteFile();
var set = null;
var array = null;

// with the show header parameter set to true the first row will will show in the result

// create a dataset from the file
// the show header parameter is set to false by default
// REMARK: a header will always be constructed from the first row
// set = plugins.it2be_data.csv().getDataSet(filePath);

// or retreive it with the delimiter set to a comma
set = plugins.it2be_data.csv().getDataSet(filePath, ",");

// create a two dimensional array from the file
// the show header parameter is set to true by default
array = plugins.it2be_data.csv().getArray(filePath, true);

// when the dataset is NOT empty
if (set.getMaxRowIndex()) {
var message = "";

// output to the debugger to show there is a result
application.output("set.getMaxRowIndex() = " + set.getMaxRowIndex());

// because the set is a 'standard' JSDataSet all the functions and properties
// we can use the Database Manager to retrieve the column count and column names
var columncount = set.getMaxColumnIndex();

// limit the number of columns we show to 5 when columncount > 5
// 5 is an arbitrary value to limit the width of the dialog
columncount = (columncount > 5) ? 5 : columncount;

// loop through the columns
for (var i = 1 ; i <= columncount ; i++) {
// retreive the names
message += set.getColumnName(i) + "::";
}
message += "\n";

// JSDataSet.sort(number, boolean) is also valid
set.sort(1, false);

var rowcount = (set.getMaxRowIndex() > 5) ? 5 : set.getMaxRowIndex();

// loop through the rows of the JSDataSet
// REMARK: the JSDataSet starts counting at 1 instead of 0
for (var i = 1 ; i <= rowcount ; i++) {
// loop through the columns
for (var ii = 1 ; ii <= columncount ; ii++) {
// and retreive the column values
message += set.getValue(i, ii) + "::";
}
message += "\n";
}

// show the result
if (message) {
plugins.dialogs.showInfoDialog("JSDataSet", message);
}
} else {
// output to the debugger to show there is NO result
application.output("JSDataSet = null");
}

// when the array is NOT empty
if (array) {
var message = "";

application.output("array.length = " + array.length);

// because the show header parameter is set to false with a (two dimensional) array
// the first row will NOT show in the array

// limit the column and row count for display purposes
var columncount = (array[0].length > 5) ? 5 : array[0].length;
var rowcount = (array.length > 5) ? 5 : array.length;

// loop through the 3D array
// REMARK: an array starts at index 0
for (var i = 0 ; i < rowcount ; i++) {
for (var ii = 0 ; ii < columncount ; ii++) {
message += array[i][ii] + "::";
}
message += "\n";
}

// show the result
if (message) {
plugins.dialogs.showInfoDialog("Array", message);
}
} else {
// output to the debugger to show there is NO result
application.output("Array = null");
}
}


write
String  write( String, Object, Object, Object )
Write a CSV file.
Parameters
String  filePath  the file path
Object  value1  dataset:JSDataSet or array:Object[]
Object  value2  header:String[]
Object  value3  overwrite:boolean or delimiter:String

Returns
String  fileName String

Supported Clients
SmartClient, WebClient, NGClient

Sample
// Get a dataset based on a query on the example (crm) database
// and it2be_companies/contacts tables
var query = "SELECT c.firstname, c.lastname, o.company_name, o.description FROM it2be_contacts AS c, it2be_companies AS o WHERE c.it2be_companiesid=o.it2be_companiesid";
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(), query, null, -1);

// stop executing this method when the dataset is empty
// and show an error dialog
if (!dataset.getMaxRowIndex()) {
plugins.dialogs.showErrorDialog("Error.", "There are no records!", "OK");

Return;
}

// set the name of the file
var file = plugins.file.showFileSaveDialog();

// get the name of the operating system to know how to execute the,
// to the filetype attached,application
var osname = application.getOSName();

// check that we really selected a file
// if not ignore the rest of the code
if (file) {
var filePath = file.getAbsoluteFile();
// create the header as a 2 dimentional array
// it is also possible to create a 3 dimensional array (see example dbf)
// in that case the rest of the data is ignored when not creating a dbf file
var header = ["firstname","lastname","company","description"];

// we can use either a 2D array or a dataset for input
// you would typically use a 2D array from data you can not retreive from the database
// in the below example we will create a 2D array from a dataset
// just to show you how to do it
var selection = new Array();

for (var i = 1 ; i <= dataset.getMaxRowIndex() ; i++) {
var row = dataset.getRowAsArray(i);

selection[i - 1] = row;
}

// write the file
// filePath = plugins.it2be_data.csv().writeArray(filePath, header, selection);
// but, we won't use the above created'selection' array since a dataset can be used without creating an array
filePath = plugins.it2be_data.csv().write(filePath, header, dataset);

// by default the delimiter for a csv file is set to a semi-colon
// however it is possible to change the delimiter to, for example a comma
// the method would then be set like below
// filePath = plugins.it2be_data.csv().writeArray(filePath, header, selection);
// filePath = plugins.it2be_data.csv().write(filePath, header, dataset, ",");

// open the data in the (to the filetype attached) application
// checking the os needs to be done via evaluation of a string
// you can also use the tools plugin that will give you an integer
if (osname.indexOf("Mac") > -1) {
// mac os x
application.executeProgram("open", filePath);
} else if (osname.indexOf("Windows") > -1) {
// windows
application.executeProgram("rundll32", "url.dll,FileProtocolHandler", filePath);
} else {
// linux etc. would love to know how to do this!
}
}


write
String  write( String, Object )
Write a CSV file.
Parameters
String  filePath  the file path
Object  dataset  the dataset

Returns
String  fileName String

Supported Clients
SmartClient, WebClient, NGClient

Sample
// Get a dataset based on a query on the example (crm) database
// and it2be_companies/contacts tables
var query = "SELECT c.firstname, c.lastname, o.company_name, o.description FROM it2be_contacts AS c, it2be_companies AS o WHERE c.it2be_companiesid=o.it2be_companiesid";
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(), query, null, -1);

// stop executing this method when the dataset is empty
// and show an error dialog
if (!dataset.getMaxRowIndex()) {
plugins.dialogs.showErrorDialog("Error.", "There are no records!", "OK");

Return;
}

// set the name of the file
var file = plugins.file.showFileSaveDialog();

// get the name of the operating system to know how to execute the,
// to the filetype attached,application
var osname = application.getOSName();

// check that we really selected a file
// if not ignore the rest of the code
if (file) {
var filePath = file.getAbsoluteFile();
// create the header as a 2 dimentional array
// it is also possible to create a 3 dimensional array (see example dbf)
// in that case the rest of the data is ignored when not creating a dbf file
var header = ["firstname","lastname","company","description"];

// we can use either a 2D array or a dataset for input
// you would typically use a 2D array from data you can not retreive from the database
// in the below example we will create a 2D array from a dataset
// just to show you how to do it
var selection = new Array();

for (var i = 1 ; i <= dataset.getMaxRowIndex() ; i++) {
var row = dataset.getRowAsArray(i);

selection[i - 1] = row;
}

// write the file
// filePath = plugins.it2be_data.csv().writeArray(filePath, header, selection);
// but, we won't use the above created'selection' array since a dataset can be used without creating an array
filePath = plugins.it2be_data.csv().write(filePath, header, dataset);

// by default the delimiter for a csv file is set to a semi-colon
// however it is possible to change the delimiter to, for example a comma
// the method would then be set like below
// filePath = plugins.it2be_data.csv().writeArray(filePath, header, selection);
// filePath = plugins.it2be_data.csv().write(filePath, header, dataset, ",");

// open the data in the (to the filetype attached) application
// checking the os needs to be done via evaluation of a string
// you can also use the tools plugin that will give you an integer
if (osname.indexOf("Mac") > -1) {
// mac os x
application.executeProgram("open", filePath);
} else if (osname.indexOf("Windows") > -1) {
// windows
application.executeProgram("rundll32", "url.dll,FileProtocolHandler", filePath);
} else {
// linux etc. would love to know how to do this!
}
}


write
String  write( String, Object, Object )
Write a CSV file.
Parameters
String  filePath  the file path
Object  value1  dataset:JSDataSet or array:Object[]
Object  value2  overwrite:boolean or delimiter:String or header:String[]

Returns
String  fileName String

Supported Clients
SmartClient, WebClient, NGClient

Sample
// Get a dataset based on a query on the example (crm) database
// and it2be_companies/contacts tables
var query = "SELECT c.firstname, c.lastname, o.company_name, o.description FROM it2be_contacts AS c, it2be_companies AS o WHERE c.it2be_companiesid=o.it2be_companiesid";
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(), query, null, -1);

// stop executing this method when the dataset is empty
// and show an error dialog
if (!dataset.getMaxRowIndex()) {
plugins.dialogs.showErrorDialog("Error.", "There are no records!", "OK");

Return;
}

// set the name of the file
var file = plugins.file.showFileSaveDialog();

// get the name of the operating system to know how to execute the,
// to the filetype attached,application
var osname = application.getOSName();

// check that we really selected a file
// if not ignore the rest of the code
if (file) {
var filePath = file.getAbsoluteFile();
// create the header as a 2 dimentional array
// it is also possible to create a 3 dimensional array (see example dbf)
// in that case the rest of the data is ignored when not creating a dbf file
var header = ["firstname","lastname","company","description"];

// we can use either a 2D array or a dataset for input
// you would typically use a 2D array from data you can not retreive from the database
// in the below example we will create a 2D array from a dataset
// just to show you how to do it
var selection = new Array();

for (var i = 1 ; i <= dataset.getMaxRowIndex() ; i++) {
var row = dataset.getRowAsArray(i);

selection[i - 1] = row;
}

// write the file
// filePath = plugins.it2be_data.csv().writeArray(filePath, header, selection);
// but, we won't use the above created'selection' array since a dataset can be used without creating an array
filePath = plugins.it2be_data.csv().write(filePath, header, dataset);

// by default the delimiter for a csv file is set to a semi-colon
// however it is possible to change the delimiter to, for example a comma
// the method would then be set like below
// filePath = plugins.it2be_data.csv().writeArray(filePath, header, selection);
// filePath = plugins.it2be_data.csv().write(filePath, header, dataset, ",");

// open the data in the (to the filetype attached) application
// checking the os needs to be done via evaluation of a string
// you can also use the tools plugin that will give you an integer
if (osname.indexOf("Mac") > -1) {
// mac os x
application.executeProgram("open", filePath);
} else if (osname.indexOf("Windows") > -1) {
// windows
application.executeProgram("rundll32", "url.dll,FileProtocolHandler", filePath);
} else {
// linux etc. would love to know how to do this!
}
}


write
String  write( String, Array<Object>, Object, Boolean, String )
Write a CSV file.
Parameters
String  filePath  the file path
Array<Object>  header  the header
Object  dataset  the dataset
Boolean  overwrite  the overwrite
String  delimiter  the delimiter

Returns
String  fileName String

Supported Clients
SmartClient, WebClient, NGClient

Sample
// Get a dataset based on a query on the example (crm) database
// and it2be_companies/contacts tables
var query = "SELECT c.firstname, c.lastname, o.company_name, o.description FROM it2be_contacts AS c, it2be_companies AS o WHERE c.it2be_companiesid=o.it2be_companiesid";
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(), query, null, -1);

// stop executing this method when the dataset is empty
// and show an error dialog
if (!dataset.getMaxRowIndex()) {
plugins.dialogs.showErrorDialog("Error.", "There are no records!", "OK");

Return;
}

// set the name of the file
var file = plugins.file.showFileSaveDialog();

// get the name of the operating system to know how to execute the,
// to the filetype attached,application
var osname = application.getOSName();

// check that we really selected a file
// if not ignore the rest of the code
if (file) {
var filePath = file.getAbsoluteFile();
// create the header as a 2 dimentional array
// it is also possible to create a 3 dimensional array (see example dbf)
// in that case the rest of the data is ignored when not creating a dbf file
var header = ["firstname","lastname","company","description"];

// we can use either a 2D array or a dataset for input
// you would typically use a 2D array from data you can not retreive from the database
// in the below example we will create a 2D array from a dataset
// just to show you how to do it
var selection = new Array();

for (var i = 1 ; i <= dataset.getMaxRowIndex() ; i++) {
var row = dataset.getRowAsArray(i);

selection[i - 1] = row;
}

// write the file
// filePath = plugins.it2be_data.csv().writeArray(filePath, header, selection);
// but, we won't use the above created'selection' array since a dataset can be used without creating an array
filePath = plugins.it2be_data.csv().write(filePath, header, dataset);

// by default the delimiter for a csv file is set to a semi-colon
// however it is possible to change the delimiter to, for example a comma
// the method would then be set like below
// filePath = plugins.it2be_data.csv().writeArray(filePath, header, selection);
// filePath = plugins.it2be_data.csv().write(filePath, header, dataset, ",");

// open the data in the (to the filetype attached) application
// checking the os needs to be done via evaluation of a string
// you can also use the tools plugin that will give you an integer
if (osname.indexOf("Mac") > -1) {
// mac os x
application.executeProgram("open", filePath);
} else if (osname.indexOf("Windows") > -1) {
// windows
application.executeProgram("rundll32", "url.dll,FileProtocolHandler", filePath);
} else {
// linux etc. would love to know how to do this!
}
}


writeArray
String  writeArray( String, Array<Object>, Array<Array<Object>>, Object )
Write a CSV file.
Parameters
String  filePath  the file path
Array<Object>  header  the header
Array<Array<Object>>  array  the array
Object  value  overwrite:boolean or delimiter: String

Returns
String  fileName String

Supported Clients
SmartClient, WebClient, NGClient

Sample
// Get a dataset based on a query on the example (crm) database
// and it2be_companies/contacts tables
var query = "SELECT c.firstname, c.lastname, o.company_name, o.description FROM it2be_contacts AS c, it2be_companies AS o WHERE c.it2be_companiesid=o.it2be_companiesid";
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(), query, null, -1);

// stop executing this method when the dataset is empty
// and show an error dialog
if (!dataset.getMaxRowIndex()) {
plugins.dialogs.showErrorDialog("Error.", "There are no records!", "OK");

Return;
}

// set the name of the file
var file = plugins.file.showFileSaveDialog();

// get the name of the operating system to know how to execute the,
// to the filetype attached,application
var osname = application.getOSName();

// check that we really selected a file
// if not ignore the rest of the code
if (file) {
var filePath = file.getAbsoluteFile();
// create the header as a 2 dimentional array
// it is also possible to create a 3 dimensional array (see example dbf)
// in that case the rest of the data is ignored when not creating a dbf file
var header = ["firstname","lastname","company","description"];

// we can use either a 2D array or a dataset for input
// you would typically use a 2D array from data you can not retreive from the database
// in the below example we will create a 2D array from a dataset
// just to show you how to do it
var selection = new Array();

for (var i = 1 ; i <= dataset.getMaxRowIndex() ; i++) {
var row = dataset.getRowAsArray(i);

selection[i - 1] = row;
}

// write the file
// filePath = plugins.it2be_data.csv().writeArray(filePath, header, selection);
// but, we won't use the above created'selection' array since a dataset can be used without creating an array
filePath = plugins.it2be_data.csv().write(filePath, header, dataset);

// by default the delimiter for a csv file is set to a semi-colon
// however it is possible to change the delimiter to, for example a comma
// the method would then be set like below
// filePath = plugins.it2be_data.csv().writeArray(filePath, header, selection);
// filePath = plugins.it2be_data.csv().write(filePath, header, dataset, ",");

// open the data in the (to the filetype attached) application
// checking the os needs to be done via evaluation of a string
// you can also use the tools plugin that will give you an integer
if (osname.indexOf("Mac") > -1) {
// mac os x
application.executeProgram("open", filePath);
} else if (osname.indexOf("Windows") > -1) {
// windows
application.executeProgram("rundll32", "url.dll,FileProtocolHandler", filePath);
} else {
// linux etc. would love to know how to do this!
}
}


writeArray
String  writeArray( String, Array<Object>, Array<Array<Object>>, Boolean, String )
Write a CSV file.
Parameters
String  filePath  the file path
Array<Object>  header  the header
Array<Array<Object>>  array  the array
Boolean  overwrite  the overwrite
String  delimiter  the delimiter

Returns
String  fileName String

Supported Clients
SmartClient, WebClient, NGClient

Sample
// Get a dataset based on a query on the example (crm) database
// and it2be_companies/contacts tables
var query = "SELECT c.firstname, c.lastname, o.company_name, o.description FROM it2be_contacts AS c, it2be_companies AS o WHERE c.it2be_companiesid=o.it2be_companiesid";
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(), query, null, -1);

// stop executing this method when the dataset is empty
// and show an error dialog
if (!dataset.getMaxRowIndex()) {
plugins.dialogs.showErrorDialog("Error.", "There are no records!", "OK");

Return;
}

// set the name of the file
var file = plugins.file.showFileSaveDialog();

// get the name of the operating system to know how to execute the,
// to the filetype attached,application
var osname = application.getOSName();

// check that we really selected a file
// if not ignore the rest of the code
if (file) {
var filePath = file.getAbsoluteFile();
// create the header as a 2 dimentional array
// it is also possible to create a 3 dimensional array (see example dbf)
// in that case the rest of the data is ignored when not creating a dbf file
var header = ["firstname","lastname","company","description"];

// we can use either a 2D array or a dataset for input
// you would typically use a 2D array from data you can not retreive from the database
// in the below example we will create a 2D array from a dataset
// just to show you how to do it
var selection = new Array();

for (var i = 1 ; i <= dataset.getMaxRowIndex() ; i++) {
var row = dataset.getRowAsArray(i);

selection[i - 1] = row;
}

// write the file
// filePath = plugins.it2be_data.csv().writeArray(filePath, header, selection);
// but, we won't use the above created'selection' array since a dataset can be used without creating an array
filePath = plugins.it2be_data.csv().write(filePath, header, dataset);

// by default the delimiter for a csv file is set to a semi-colon
// however it is possible to change the delimiter to, for example a comma
// the method would then be set like below
// filePath = plugins.it2be_data.csv().writeArray(filePath, header, selection);
// filePath = plugins.it2be_data.csv().write(filePath, header, dataset, ",");

// open the data in the (to the filetype attached) application
// checking the os needs to be done via evaluation of a string
// you can also use the tools plugin that will give you an integer
if (osname.indexOf("Mac") > -1) {
// mac os x
application.executeProgram("open", filePath);
} else if (osname.indexOf("Windows") > -1) {
// windows
application.executeProgram("rundll32", "url.dll,FileProtocolHandler", filePath);
} else {
// linux etc. would love to know how to do this!
}
}