Velocity Report with download link

Hello Everybody
Servoy 6.0.3 Webclient

I show a velocity report in an html-aera on my form :

vhtml = plugins.VelocityReport.renderTemplate("PasProdukte.html", m_produktinfos(), resolution);

In my PasProdukte.html i have this to show some links and offer them to download

 <tbody>
  #foreach($record in $datasetd)
   
    <tr>
     <td><a href="javascript:m_dateiDownload('$record.PRODUKTDOKUMENT')">$record.PRODUKTDOKUMENT</a></td>
     <td>$record.DOKUMENTTYP</td>
    </tr>
  #end
  </tbody>

In my m_dateiDownload i do:

  function m_dateiDownload(vdokument) {
	var file = plugins.file.convertToJSFile(vdokument);
	plugins.file.writeFile(file.getName(), file.getBytes());
}

In the html-aera the table with the records of datasetd are shown as expected:
\fileserver\dir\dir\filename.pdf

But in my method vdokument has:
fileserverdirdirfilename.pdf = missing backslashes ???

After hours of testing i found a workaround to get the needed string for the download method.
In my data collecting method i do something like this:

 var  pdquery = "select produktdoktyp.dokumenttyp,produktdokumente.produktdokument,NULL as dummy "+
" from produktdokumente join produktdoktyp on produktdoktyp.produktdoktypid = produktdokumente.produktdoktypid "+
"where produktstammid = '"+vproduktid+"'";
	
//the dummy column gets the manipulated string	
	
var pddataset = databaseManager.getDataSetByQuery("maxdb",pdquery,null,-1);
for (var i = 1 ; i <= pddataset.getMaxRowIndex() ; i ++ )
 {
var pdpfad = pddataset.getValue(i,2);
pdpfad = utils.stringIndexReplace(pdpfad,1,2,'\\\\vm-s-file1\\pb-allgem');         // changing mapped directory x: to fileservername\wantedDirectory
pddataset.setValue(i,2,pdpfad);
var vdummy = utils.stringReplace(pdpfad, '\\','//');   // putting the needed string for downloading into the column dummy
pddataset.setValue(i,3,vdummy);
}

context.datasetd = pddataset;

Finaly i had to change my PasProdukte.html

#foreach($record in $datasetd)
 <tr>
  <td><a href="javascript:m_dateiDownload('$record.DUMMY')">$record.PRODUKTDOKUMENT</a></td>
  <td>$record.DOKUMENTTYP</td>
  </tr>
  #end

Strange !!!

Why does

$record.PRODUKTDOKUMENT return produktdokument without slashes to my m_dateiDownload method??

Couldn’t this one be easier ??
Did i miss something??

Regards
Albert

\ in a Java string usually means an escaped char. \ is translated to just one \
In Java, if you want two backslashes \, your need to put 4 in your String \\
That’s just standard Java behavior…

Now to make this thing A LOT easier, since you are basically working with a record, I would just pass the PK of that record to the method then safely retrieve the record document path in Servoy, so the context would be created as:

var pdquery = 'select produktdoktyp.dokumenttyp,produktdokumente.produktdokument,produktdokumente.produktdoktypid \
 from produktdokumente join produktdoktyp on produktdoktyp.produktdoktypid = produktdokumente.produktdoktypid \
where produktstammid = ?';
//Better use the param array than concatenate yourself, so use ? in the SQL and then do:   
var pddataset = databaseManager.getDataSetByQuery("maxdb",pdquery,[vproduktid],-1);
context.datasetd = pddataset;

Then the template would contain:

<td><a href="javascript:m_dateiDownload($record.produktdoktypid)">$record.PRODUKTDOKUMENT</a></td>

Then m_dateiDownload would be something like this:

function m_dateiDownload(id) {
    if (id) {
        var  pdquery = "select produktdokument from produktdoktyp where produktdoktypid  = ?";
        var pddataset = databaseManager.getDataSetByQuery("maxdb",pdquery,[id],1);
        if (pddataset) {
            var vdokument = pddataset.getValue(1,1);
            if (vdokument) {
                var file = plugins.file.convertToJSFile(vdokument);
                plugins.file.writeFile(file.getName(), file.getBytes());
            }
        }
    }
}