Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Initialize script
ajunuthula
Hi,
I have this code in the Initialize Script:
importPackage(Packages.java.io);
var log = new FileWriter("c:\\" + "params_save" + ".txt",true);
log.write("From(year)\t");
log.write("To(year)\t");
log.write("Author#1\t");
log.write("Author#2\t");
log.write("Author#3\t");
log.write("Author#4\r\n");
log.write( params["From(year)"] + "\t\t");
log.write( params["To(year)"] + "\t\t");
log.write( params["Author#1"] + "\t");
log.write( params["Author#2"] + "\t");
log.write( params["Author#3"] + "\t");
log.write( params["Author#4"] + "\t");
log.flush();
//reportContext.setGlobalVariable("logWriter", log);
Is there a way that Instead of having this code in the Initialize script, I can run this when clicked on a button in the report?
Thank you.
Find more posts tagged with
Comments
mwilliams
You might be able to create a button in a HTML text control and use scripting tags to run this script on the click of the button.
ajunuthula
Can you please post some example on how to use the scripting tags.
Thank you.
ajunuthula
Is this the correct way of using script tags:
<html>
<script>
function write(){
var log = new FileWriter("c:\\" + "params_save" + ".txt",true);
log.write("From(year)\t");
log.write("To(year)\t");
log.write("Author#1\t");
log.write("Author#2\t");
log.write("Author#3\t");
log.write("Author#4\r\n");
log.write( params["From(year)"] + "\t\t");
log.write( params["To(year)"] + "\t\t");
log.write( params["Author#1"] + "\t");
log.write( params["Author#2"] + "\t");
log.write( params["Author#3"] + "\t");
log.write( params["Author#4"] + "\t");
log.flush();
}
</script>
<input type="button" value="save" onclick="write()
</html>
ajunuthula
Or is there a way as:
In the initialize script, enclose the code inside a function and then call or access this function when clicked on html button.
Any help is greatly appreciated.
Thank you.
ajunuthula
Hi,
I can create the text file when clicked on a button using the code as below:
<head>
<script language="javascript">
function WriteToFile(){
var fso = new ActiveXObject("Scripting.FileSystemObject");
var s = fso.CreateTextFile("C:\\Test.txt", true);
s.WriteLine(params["Author#1"]);
s.Close();
}</script>
<input type="button" value="Save" onclick="WriteToFile()"
But I cannot write the value of the parameter author#1 to the file.
Is the syntax "s.WriteLine(params["Author#1"])" correct?
Thank you.
mwilliams
I have not done this before, so I'm not sure, but you might need to use the <value-of> tag to get the parameter information. Give it a try and let me know.
ajunuthula
I am not sure if the syntax is correct. I tried the following but no luck.
<head>
<script language="javascript">
function WriteToFile(){
var fso = new ActiveXObject("Scripting.FileSystemObject");
var s = fso.CreateTextFile("C:\\Test.txt", true);
s.WriteLine<VALUE-OF>params["To"]</VALUE-OF>
s.Close();
}</script>
<input type="button" value="Save" onclick="WriteToFile()"
ajunuthula
I solved it, am copying the parameter value into variable and then writing the variable to the text file.
The code is below:
<head>
<script language="javascript">
function WriteToFile(){
var fso = new ActiveXObject("Scripting.FileSystemObject");
var s = fso.CreateTextFile("C:\\Test1.txt", true);
s.WriteLine('Hello Aparna');
var i = <VALUE-OF>params["To"]</VALUE-OF>
s.WriteLine(i);
s.Close();
}</script>
<input type="button" value="Save" onclick="WriteToFile()"
Thank you.
mwilliams
Perfect! You're welcome!