plugin.textxport: Get rid of the quotation marks (")

Questions and answers on developing, deploying and using plugins and JavaBeans

plugin.textxport: Get rid of the quotation marks (")

Postby d.kull » Wed Nov 09, 2016 7:34 pm

Hi,

I can't find a way to get rid of the quotation marks in a simple textxport. The integers comes ok - but the text has the quotation marks. If I do the same thing with the excelxport-plugin it comes with out any. But since I need a text file with no header I thought the textxport-plugin is more suitable. Can some give me advise?

Here is the code:

/**

* @private
* @properties={typeid:24,uuid:"CCA2704B-A1FA-4679-AC61-1F46779A04B6"}
*/
function ExportTxtFile()
{
var $saveToLocation = plugins.file.showDirectorySelectDialog()
if(!$saveToLocation)return;

$saveToLocation+='debi_dump_.txt';

var bytes = plugins.textxport.textExport(forms.lst_debi_journal_all_2.foundset,
[
'exp_rechnungsdatum_txt',
'd_bu_soll',
'd_bu_haben',
'belegnummer',
'd_bu_buchungstext',
'd_bu_rechnungsbetrag2',
'scopes.globals.const_zero',
'scopes.globals.const_zero',
'scopes.globals.const_zero',
'scopes.globals.const_one',
'scopes.globals.const_one',
'scopes.globals.const_null',
'scopes.globals.MwstCodeUst',
'd_bu_geschaeftsbereich_id'],';');

var success = plugins.file.writeTXTFile($saveToLocation, bytes);
if (!success) application.output('Could not write file.');
}

Thanks,

Dominique
d.kull
 
Posts: 10
Joined: Mon Mar 21, 2016 3:13 pm

Re: plugin.textxport: Get rid of the quotation marks (")

Postby Andrei Costescu » Thu Nov 10, 2016 11:11 am

The plugin doesn't provide a way to get rid of the quotation marks around strings.
So you can either create a feature request or generate the text export string yourself if you really need that.
Andrei Costescu
Servoy
Andrei Costescu
 
Posts: 1018
Joined: Tue Jun 26, 2007 3:14 pm

Re: plugin.textxport: Get rid of the quotation marks (")

Postby marco.rossi » Thu Nov 10, 2016 11:45 am

You can write the string export as suggested by Andrei (the best way) but
if you don't want to generate the string by yourself, you can obtain a result with 2 steps:

1 - Write the file generated by the "extxport" plugin as you've done.
2 - Read the written file and just remove the all the quotation marks like follows:

while(_readedStringFile.indexOf('"') // is the " char between two ' ' single apex
_readedStringFile = _readedStringFile.replace('"','')


3- Write the clean file again

Not very elengant in real but it should work.
Marco Rossi
Senior Analyst Developer
Freelance Consultant

IT Manager @Mantho
Webmaster @Sitoliquido
marco.rossi
 
Posts: 110
Joined: Sun Apr 12, 2015 9:33 pm

Re: plugin.textxport: Get rid of the quotation marks (")

Postby Andrei Costescu » Thu Nov 10, 2016 2:52 pm

I thought of that initially and something like that can be done.
But your solution would break data strings that have quotation marks in them.

So the parsing needs to be more intelligent Something like only remove the marks after the separator char at the beginning and then only if last char in there is ".
That's why I suggested just building it in code - it might be easier then parsing the result and removing the unwanted quotes.

See populateFileData in https://github.com/Servoy/servoy-extens ... Panel.java for inspiration :). Method is quite small.
Andrei Costescu
Servoy
Andrei Costescu
 
Posts: 1018
Joined: Tue Jun 26, 2007 3:14 pm

Re: plugin.textxport: Get rid of the quotation marks (")

Postby d.kull » Fri Nov 11, 2016 12:16 pm

By looking again in the depth of the forum I found the way by doing it with dataset. Here is what I merged of this:

/**

* @private
*
* @properties={typeid:24,uuid:"6249CE38-DDE8-48C1-92F4-9CEF77EB2794"}
*/

function Export1000 ()
{
var $saveToLocation = plugins.file.showDirectorySelectDialog()
if(!$saveToLocation)return;

$saveToLocation+='debi_dump_.txt';

var dataset = databaseManager.convertToDataSet(forms.lst_debi_journal_all_2.foundset,new Array(

'exp_rechnungsdatum_txt', //1 Datum der Buchung
'd_bu_soll', // 2 Sollkonto
'd_bu_haben', // 3 Habenkonto
'belegnummer', // 4 Belegnummer
'd_bu_buchungstext', // 5 Buchungstext
'd_bu_rechnungsbetrag2', // 6 Rechnungsbetrag
'scopes.globals.const_zero', //7 Fremdwährung 0=keine
'scopes.globals.const_zero', // 8 Wechselkurs 0=keiner
'scopes.globals.const_zero', // 9 Nr Sammelbuchung
'scopes.globals.const_one', // 10 brutto / netto MWST
'scopes.globals.const_one', // 11 MWST Kontrollkaestchen
'belegnummer', // 12 Nr MWST Buchung
'scopes.globals.MwstCodeUst', // 13 MWST Code
'scopes.globals.const_null', // 14 leer
'd_bu_geschaeftsbereich_id')); // 15 Analytik-Code

var form_data = dataset.getAsText('\t','\r\n','', false);
var success = plugins.file.writeTXTFile($saveToLocation, form_data);

if (!success) application.output('Could not write file.');

}

I have tested it with ~10'000 rows and performance was ok for me - not even enough time for a coffee.

Thank you all for helping me.

Dominique
d.kull
 
Posts: 10
Joined: Mon Mar 21, 2016 3:13 pm

Re: plugin.textxport: Get rid of the quotation marks (")

Postby d.kull » Fri Nov 11, 2016 12:25 pm

By looking through my code I found a 'dead-function' which never seems to work. But it looks also kind of interesting.

Problems:
The method split() is undefined for object column names
The property length is undefined in columnArray

I think this code also captured from the forum years ago. Perhaps some of you can give a hint how to get this around - and others can learn and benefit.

Code: Select all
/**
* @properties={typeid:24,uuid:"06dfe561-8ab3-46bd-8adc-db3aead59592"}
*/
function createExportFile()
{
var form = arguments[0]
var fieldnames = arguments[1]    // boolean, export with ColumnNames at top
var seperator = arguments[2]    // string, choose seperator, for example:  "\t" for TAB "," or ";"
var quotes = arguments[3]       // boolean, ColumnNames with quotes
var columnnames = arguments[4]   // string, ColumnNames seperated by: ";"
var exportfile = ""          //  create a text variable

// set the variable insertquotes to " or nothing
if (quotes == true) var insertquotes = '"'
else  insertquotes = "";

// split the columnames into an Array
var columnArray = columnnames.split(";")
// determine how many columns are used
var columnCount = columnArray.length

// if fieldnames is true than place the ColumnNames at top
if(fieldnames == true)
{   
   for(var x=0;x<= columnCount-1;x++)
   {
      if(x != columnCount-1) exportfile += columnArray[x] + seperator
      else exportfile += columnArray[x]
   }
// make an 'Enter'   
exportfile += "\r\n"
}

// loop thru the foundset
for(var i=1;i<= forms[form].foundset.getSize();i++)
{
   var record = forms[form].foundset.getRecord(i);
   for(x=0;x<= columnCount-1;x++)
   {
      if(record[columnArray[x]])
      {
        utils.stringReplace(record[columnArray[x]],'\r\n', '')
      if(x != columnCount-1) exportfile += insertquotes + record[columnArray[x]] + insertquotes + seperator
         else exportfile += insertquotes + record[columnArray[x]] + insertquotes
      }
      else
      {
         if(x != columnCount-1) exportfile += insertquotes + seperator
         else exportfile += insertquotes
      }
   }
   exportfile += "\r\n"
}

//open dialog, with a suggested filename
var save = plugins.file.showFileSaveDialog('file_export.mer')
if(save != null)
{
   var success =plugins.file.showFileSaveDialog(exportfile);
   if (success)
   {
      plugins.dialogs.showInfoDialog('Info', 'The File is saved!','OK');
   }
   else
   {
      plugins.dialogs.showErrorDialog('Warning', 'The File is NOT saved because of an error!','OK');
   }
}
}


Cheers

Dominique
d.kull
 
Posts: 10
Joined: Mon Mar 21, 2016 3:13 pm


Return to Plugins and Beans

Who is online

Users browsing this forum: No registered users and 15 guests