Javascript to send score to external program

Sep 18, 2012

Hi, Storyline Fans -

I'm assisting a colleague with a bit of coding in an effort to capture the score from a Storyline quiz, and save it in a database (along with employee name, ID, date/time stamp, etc.).  I do not use Storyline - but I have developed a series of ASP programs that did a similar function with Presenter and Quizmaker products.

From the discussions I've found here, it appears that you can attach Javascript code to triggers associated with controls that you define on your Storyline screens.  Assuming that a "Submit Results" button has been defined on the final slide of a Storyline quiz (so, results have been displayed to the user) - can the following code be attached to a trigger in order to successfully pass the score to an external program?

Here is the code:

// get Storyline player

var p.GetPlayer();

// get score

var score = p.GetVar("Results.ScorePercent");

// pass score to ASP program to eventual database update

var sHTML = "";

sHTML += '<form id="formScore" method="post" action="/PathToProgram/SL_Post_Scores.asp">';

sHTML += 'input type="hidden" id="Score" name="Score" value= ' " + score + " '>';

sHTML += '<br><input type="submit"><br>';

sHTML += '<form>';

document.getElementById("formScore").submit();

The SL_Post_Scores.asp program will prompt the user to enter the network login ID and password; validate their credentials against our Company's Active Directory; and - if valid - retrieve their score (using Request.Form("Score") and other employee demographics and insert it into a database that stores all of our exam/quiz results (we're replacing this interim solution with the Cornerstone LMS soon - but not soon enough!).  Does anyone see any problems with this approach?

45 Replies
Jeff Furumura

We are successfully able to exit from our Storyline courses to an ASP program now - but I am unable to obtain the Storyline variable containing the score.

The code below works - but passes only a dummy value of "999."  When we uncomment the lines that should provide the Storyline variable values (e.g., GetVar("Results.ScorePercent") - nothing gets passed.

Does anyone have any suggestions?

Here is the working code from our User.js module:

function ExecuteScript(strId)
{
  switch (strId)
  {
      case "61uF56TN3U2":
        Script1();
        break;
  }
}

function Script1()
{
  // get Storyline player
var player = GetPlayer();

// get score
//var score = player.GetVar("Results.ScorePercent");
var score = 999;

//display value on screen
//alert("Score to be passed: " + score);

// pass score to ASP program for eventual database update
var sHTML = "";
sHTML += '';
sHTML += '';
sHTML += '

';
sHTML += '';
document.getElementById("divEmail").innerHTML = sHTML;
document.getElementById("formScore").submit();
}

Jeff Furumura

Thanks for the reply, Phil - but I thought the following line of code from above is "...set(ting) another variable in Storyline to the value of score.percent":

     var score = player.GetVar("Results.ScorePercent")

When I un-comment that line and attempt to display the variable using an alert - the alert command is never executed.  I don't get a syntax error (I'm using Dreamweaver) on the code either, so I'm kinda puzzled as to what's going on.

When I use the hardcoded value of 999 (as above) - the 999 value is successfully being passed to an external program and winds up being saved in a database along with associated employee demographic details.  This is being done as a temporary way to store course completion data...until our LMS comes online next year.

Please let me know if you have any insights!

Mahalo plenty,

Jeff

Jeff Furumura

After re-reading your post, Phil, I finally GOT what you were saying to me.

I downloaded a trial of Storyline - and defined a variable INSIDE of a quickie test quiz to hold the Results.Scorepercent value.

Then, my Javascript trigger captures that internally-defined variable (and NOT the Results.Scorepercent) and passes that along to my database program.  So easy!

In case others have similar needs, I've attached my test Storyline file.  If you have access to your own IIS server and can execute ASP programs (ASP 3.0, aka ASP Classic), please message me for the little database update program I've put together (along with a dump utility so users can see who has attempted the test and the results).

Jeff Furumura

Hi, Stefano -

Hmmm, I've tried to get the Little Paperclip icon to work for me - but nothing seems to upload.

I will message you directly and provide you with the Word document that I put together to provide to our eLearning author.  The document explains step-by-step how to prepare the variables to be sent to an external database...and includes the javascript to insert as well.

I also have the ASP programs that were written for our environment here, if you want to see how they're put together.  But I think the document explains their function clearly enough.

Thanks,

Jeff

Deepak G.C

Jeff Furumura said:

Hi, Stefano -

Hmmm, I've tried to get the Little Paperclip icon to work for me - but nothing seems to upload.

I will message you directly and provide you with the Word document that I put together to provide to our eLearning author.  The document explains step-by-step how to prepare the variables to be sent to an external database...and includes the javascript to insert as well.

I also have the ASP programs that were written for our environment here, if you want to see how they're put together.  But I think the document explains their function clearly enough.

Thanks,

Jeff

Hi Jeff,

I tried your solution on latest storyline app and it does work , I am able to get the score value but only in html5.html in story.html(flash) the GetPlayer() returns an empty object..  :(

Thanks,

Deepak G.C

Jeff Furumura

I hope it still works, Rob.  I do not own a copy of Storyline - but was asked by our trainers to come up with a way to capture Storyline variables onine in a little database...while they waited for our full-blown LMS system to be stood-up.  It worked while it lasted - but Storyline may have undergone modification since this was written that may make some of the instructions no longer relevant.  I hope not - but, there you go.

Good luck in your project!

Jeff

Richard Stanford

Hi Jeff -

I hope you're still monitoring this thread.  I've looked at your Word file and I think I understand most of it.  I haven't done programming in a long while (and then only FORTRAN and Visual Basic) - and I have never done Javascript or set up an .asp.

I'd just like to have Storyline send me an e-mail with the information (plus some other stuff) that you've captured in your Javascript.  So - my question - rather than send the information to an .asp application that will write it to a dbf, can I simply use a mailto command to send the information in a message to my e-mail address?

If not - can you please send me the coding for the three .asp routines?  I'm not exactly sure what the SL_Login2.asp routine does/will do.  Why does the User need to present his/her network login credentials?  Perhaps I really don't need that portion of the execution chain.

Anyway - I'm not on a network.  I hope to use Storyline to show lessons to my students who will access the Storybook lesson from a link on my class web page.  The students will take quizzes after each lesson - and then I hope to have Storyline e-mail me the results of those quizzes.  It's an attempt to 'flip' my classroom; the quizzes will be confirmation that the students have watched/read the lesson materials in preparation for the next day's in-class discussion and activities.

Thanks.

Steve Flowers

There are two pieces to getting "send to spreadsheet" to work.

  • The first is setting up the spreadsheet to catch the values. Create your spreadsheet with your field names in the first row. The names are important but you can use whatever you want. Next you'll need to add some Apps Script to catch the values and place them in the spreadsheet. See the tutorial here for a description of how to do that: http://mashe.hawksey.info/2011/10/google-spreadsheets-as-a-database-insert-with-apps-script-form-postget-submit-method
  • The next piece is setting up Storyline to send. You have two options here. One is to add a library like Jquery and POST the data through an Ajax call. The other is to dynamically create an iFrame on the page and set the URL of the iFrame to your apps script address extended with name value pairs, using GET. The Ajax call is cleaner, the iFrame querystring version is simpler to implement.

The code you'd use depends a lot on your implementation.

Jeff Furumura

Hi, Richard (who posted way back on Aug 25 2013) -

My apologies for not monitoring this thread and seeing your request.  I'll be sending you a private message with the sample modules attached (hope your email address is still current).

As for why it is necessary for the users to log in:  The programs reside on our network and any of our employees can take the Storyline course.  When it comes time to capture their quiz scores - the program needs to authenticate them (as being employees), and at the same time it uses this info to look-up their employee demographic data (job title, supervisor name, work site address , etc.).  Then it folds this data together with the quiz scores to create and insert a new row into the database.

I hope the module still works with the current version of Storyline.  As I noted earlier - I am not a Storyline user, but just the tech resource for our Training team. 

Mark Woolwine

Steve Flowers said:

There are two pieces to getting "send to spreadsheet" to work.

  • The first is setting up the spreadsheet to catch the values. Create your spreadsheet with your field names in the first row. The names are important but you can use whatever you want. Next you'll need to add some Apps Script to catch the values and place them in the spreadsheet. See the tutorial here for a description of how to do that: http://mashe.hawksey.info/2011/10/google-spreadsheets-as-a-database-insert-with-apps-script-form-postget-submit-method
  • The next piece is setting up Storyline to send. You have two options here. One is to add a library like Jquery and POST the data through an Ajax call. The other is to dynamically create an iFrame on the page and set the URL of the iFrame to your apps script address extended with name value pairs, using GET. The Ajax call is cleaner, the iFrame querystring version is simpler to implement.

The code you'd use depends a lot on your implementation.


Steve do you think you could put together a screener on how to do this? 

This discussion is closed. You can start a new discussion or contact Articulate Support.