# Velocity Report with download link

**URL:** <https://forum.servoy.com/t/velocity-report-with-download-link/15184>\
**Category:** Classic Servoy\
**Created:** [December 15, 2011, 1:02pm UTC](https://forum.servoy.com/t/velocity-report-with-download-link/15184 "2011-12-15T13:02:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![abeermann](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@abeermann](https://forum.servoy.com/u/abeermann)\
**Post date:** [December 15, 2011, 1:02pm UTC](https://forum.servoy.com/t/velocity-report-with-download-link/15184/1 "2011-12-15T13:02:42Z")

</div>

Hello Everybody  
Servoy 6.0.3 Webclient

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

```auto
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

```auto
 <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:

```auto
  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:

```auto
 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

```auto
#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

---

<div class="post-metadata">

**Author:** ![ptalbot](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/ptalbot/32/4952_2.png) [@ptalbot](https://forum.servoy.com/u/ptalbot)\
**Post date:** [December 15, 2011, 2:19pm UTC](https://forum.servoy.com/t/velocity-report-with-download-link/15184/2 "2011-12-15T14:19:41Z")

</div>

\ 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:

```auto
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:

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

```

Then m\_dateiDownload would be something like this:

```auto
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());
            }
        }
    }
}

```
