Forum Discussion
using trigger javascript to read / write data into excel or other?
I know you posted this a while ago but if you still need help, I was able to write to a txt file using JavaScript. I have a button with a trigger that executes the JavaScript when pressed. This is the code with //comments to explain:
var fso = new ActiveXObject("Scripting.FileSystemObject"); //basically tells it you're using ActiveX
var s = fso.OpenTextFile("S:\\QC\\profiles\\krissymiller\\Test.txt", 8, true); //this opens the file, first is the path name (don't forget there are 2 \ and not just one, 8 means append to the file (1 is for just reading, 2 is for just writing), true means if there is no file by that name to create it, can do false to not create it
var player = GetPlayer(); //gets the player from storyline, everything comes from the player
var name = player.GetVar("username"); //gets the variable I called username
var score = player.GetVar("ScorePercent");
s.WriteLine("Name: " + name); //writes Name: name to the file on one line
s.WriteLine("Score: " + score + "%"); //writes Score: score% to the file on one line
s.WriteLine("=========="); //writes ===== just to separate the data
s.Close(); //closes the file
- StefanoTodaro11 years agoCommunity Member
Hi Krissy,
I created two variables "name" and "email" I connected to a field, then I hooked a trigger javascript to keys.
I tried to use your javascript code and I'm trying to understand why it does not work:var fso = new ActiveXObject ("Scripting.FileSystemObject");
var s = fso.OpenTextFile ("C:\\stetod.txt", 8, true);
var player = GetPlayer ();
var name = player.GetVar ("name");
var email = player.GetVar ("email");
s.WriteLine ("Email:" + e-mail);
s.WriteLine ("Name:" + name);
s.WriteLine ("==========");
s.Close ();After publishing I uploaded it to my server.
The browser is no message warning, I would not want the browser did not write the file!It seems all right but not function and do not understand why!
Do you have any idea !?
Thanks
Related Content
- 5 months ago