How to create a Text File From Server Side (Trigger) ?

Posted by Meryk on 15-Sep-2015 07:41

Hello,

I am trying to do something very simple. Create a text file and send it to a given location from a trigger.

I could do this with the Kendo function, but only client side, in a script component in a page, this way :

var dataURI = "data:text/plain;base64," + kendo.util.encodeBase64("Hello World!");
kendo.saveAs({
dataURI: dataURI,
fileName: "test.txt"
});

And it is working properly. I assume we dont have any kendo server side..

So how can I achieve this from a trigger please? I did some research and don't seem to find any native Javascript function of creating/writing/saving a file.. 

Thank you for your help.

Meryem

Posted by Srinivas Panyala on 16-Sep-2015 08:28

JavaScript in Serverside triggers is executed in Rhino scripting engine which in embedded in Rollbase Server based on Java Platform. From Rhino, you can access any Java packages as long as it is accessible from Rhino Sandbox. SO to create a file you need to invoke java.io packages which are not accessible by default.

So do the following setting to enable access. Add the following entry to shared.properties and restart.

CustomClassFilter = [java.io|java.lang].*

Now use the following JS Code in trigger

var file = new Packages.java.io.File("c:/newfile2.txt");

file.createNewFile();

Thanks

Srinivas

All Replies

Posted by Srinivas Panyala on 16-Sep-2015 08:28

JavaScript in Serverside triggers is executed in Rhino scripting engine which in embedded in Rollbase Server based on Java Platform. From Rhino, you can access any Java packages as long as it is accessible from Rhino Sandbox. SO to create a file you need to invoke java.io packages which are not accessible by default.

So do the following setting to enable access. Add the following entry to shared.properties and restart.

CustomClassFilter = [java.io|java.lang].*

Now use the following JS Code in trigger

var file = new Packages.java.io.File("c:/newfile2.txt");

file.createNewFile();

Thanks

Srinivas

This thread is closed