Javascript to send score to external program

Jeff Furumura

33 posts

Posted Tuesday, September 18, 2012 at 9:00 PM  

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?


This post has 1 verified answers

Verified Answers

User Rank Phil Mayor

9,979 posts

Posted Saturday, September 29, 2012 at 12:29 AM  

Verified Answer

I dont think you can get the score.percent direct from Storyline these seem to be protected variables, you may be able to set another variable in Storyline to the value of score.percent and then use that


All Replies

Jeff Furumura

33 posts

Posted Friday, September 28, 2012 at 7:49 PM  

Suggested Answer

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();
}


User Rank Phil Mayor

9,979 posts

Posted Saturday, September 29, 2012 at 12:29 AM  

Verified Answer

I dont think you can get the score.percent direct from Storyline these seem to be protected variables, you may be able to set another variable in Storyline to the value of score.percent and then use that


Jeff Furumura

33 posts

Posted Monday, October 01, 2012 at 7:10 PM  

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

33 posts

Posted Monday, October 01, 2012 at 9:47 PM  

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).


Posted Monday, November 19, 2012 at 3:01 AM  

Hi Jeff

I didn't find the Storyline file you said you attached. That could be very helpful to let me understand how to call an ASP.

 

Thanks for your help

stefano


Jeff Furumura

33 posts

Posted Tuesday, November 20, 2012 at 2:58 PM  

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


HowTo_StorylineSetUpToSaveVariables_2.zip
Saul Jacobs

126 posts

Posted Monday, December 03, 2012 at 2:42 AM  

Hi Jeff

I would also like to see the doc you put together that explains this. thanks.


Jeff Furumura

33 posts

Posted Monday, December 03, 2012 at 1:40 PM  

Hi, Saul -

I sent you a PM and will gladly share a working sample with you.

Thanks,

Jeff


Deepak G.C

4 posts

Posted Thursday, January 31, 2013 at 2:02 AM  

 

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


HowTo_StorylineSetUpToSaveVariables_2.zip

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

33 posts

Posted Thursday, January 31, 2013 at 1:59 PM  

Hi, Deepak G.C. -

I'll send you a PM, but in the meantime, you may want to see this remark about the limitations of GetPlayer returned variables.


Rob Hunter

1 posts

Posted Wednesday, July 17, 2013 at 8:29 PM  

Hi J. Furumura,

 

I downloaded your WORD doc. and will try it.

Thanks so much for working that out!


Jeff Furumura

33 posts

Posted Thursday, July 18, 2013 at 12:46 PM  

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


Posted Sunday, August 25, 2013 at 9:45 AM  

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.


User Rank Leslie McKerchie

9,032 posts

Posted Monday, August 26, 2013 at 5:36 AM  

Hi Richard! I wanted to pop in and welcome you to E-Learning Heroes! Not sure if Jeff is still subscribed to this thread or not, but there are many awesome users in this community that may be able to assist you. It's good to have you and again, welcome


Posted Tuesday, August 27, 2013 at 10:05 AM  

Has anyone found a way to make this work under current version of Storyline?  I would be interested in the details as this is exactly what I am trying to accomplish until our LMS comes online.


User Rank Steve Flowers

4,094 posts

Posted Tuesday, August 27, 2013 at 10:09 AM  

I've gotten Storyline connected with a Google Spreadsheet. Scores and names from SL variables posted to rows in the spreadsheet. Have used a little trickery to get variables back out of the spreadsheet as well (shouldn't be common or necessary.)


Saul Jacobs

126 posts

Posted Tuesday, August 27, 2013 at 12:58 PM  

Hi Steve

Are you using Javascript to send the variables? 

Can you share the code you use to send to Google Spreadsheet?

 

Thanks

Saul


User Rank Steve Flowers

4,094 posts

Posted Wednesday, August 28, 2013 at 3:57 AM  

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.


Saul Jacobs

126 posts

Posted Wednesday, August 28, 2013 at 4:45 AM  

Thanks Steve, will give it a try. Wish SL had a simpler built-in option though.


Jeff Furumura

33 posts

Posted Monday, October 07, 2013 at 8:58 PM  

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. 


User Rank Ashley Terwilliger

15,526 posts

Posted Tuesday, October 08, 2013 at 9:05 AM  

Thanks Jeff for coming back to update the thread, a little late is better than never.


Jeff Furumura

33 posts

Posted Tuesday, October 08, 2013 at 11:12 AM  

I failed to click the "Subscribe to this thread" button at the top, erroneously thinking that since I had started the thread, I'd be notified of any activity in it.  Doh! (headslap) 


User Rank Leslie McKerchie

9,032 posts

Posted Tuesday, October 08, 2013 at 11:16 AM  

It happens Jeff, and you actually have to re-subscribe once you respond as well. A negative result of trying to keep spammers out


Mark Woolwine

58 posts

Posted Tuesday, October 08, 2013 at 11:25 AM  

 

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? 

 


Posted Tuesday, April 08, 2014 at 12:58 AM  

Hi all

 

Is there any option to find the type of quiz (text entry,multiple choice ) in the current slide using javascript

 

Thanks in advance

Saravanan.C


Posted Wednesday, April 09, 2014 at 9:18 AM  

Hi Ramesh,I was trying to find out this same thing and found out the following information in the story.js file that is part of the published storyline output:
Testing on a two question true/false slide 1

strQuizId - hex value
strId - Scene1_Slide1_True_False_0_0
strLMSId - TrueFalse
strType - truefalse
strCorrectResponse - true //answer set to true
strUserResponse - true //answered true
nLatency - 0
strStatus - Correct
nPoints - 10
strCompletedTime - 10:23:09 //time set on comp clock
nWeight - 1
nQuestionNumber - 1
strDescription - true
strQuizName - Results
bTracked - true

Hope this may help in someway, I was having an issue getting question level data, and this looks like the place where I need to get it from.
Ketki Dave

1 posts

Posted Tuesday, August 12, 2014 at 7:41 AM  

 

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


HowTo_StorylineSetUpToSaveVariables_2.zip


Hello Jeff,

Can you please upload the zip file, as while trying to extract the contents it gives a message saying the file is damaged or corrupted.