Forum Discussion

josephrichardso's avatar
josephrichardso
Community Member
11 years ago

using trigger javascript to read / write data into excel or other?

Hi all,

I'm building a simulation in storyline, the only bit i'm stuck on is how to save data.

I'm setting variables with data inputs no problem, but then (i guess using trigger javascript) need to write and read from storyline to either excel or some other kind of data file. I'm not a coder and am struggling to get it working using any Javascript resources I can find.

Anyone had any luck getting storyline to write to and read from either text file / excel file / database or cookie etc using triggers and javascript? or if not any support in how would be be good.

Thanks

Joe

  • KrissyMiller's avatar
    KrissyMiller
    Community Member

    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

    • StefanoTodaro's avatar
      StefanoTodaro
      Community 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

  • AliAl-Shufafa's avatar
    AliAl-Shufafa
    Community Member

    I know this is an old thread but I guess others may still ask the same question.

    The export of data from SL to a local text of Excel file is possible. Many may not be able to get this functioning because they operate Chrome or other newer browsers. 

    Internet Explorer can do that because it accepts the key javascript function (ActiveXObject) while others do not.

    Another reason is the text/Excel file location. The user must have system permission to write in that location. For example, some computer configurations may prevent you from writing directly under C drive.

    I hope this helps someone.

    Ali