Matthew Bibby
Matthew Bibby

Send Question Data to the LMS When Using SCORM 1.2

In this tutorial, we will look at an easy way to prepend our question data to the learner's response so that you are able to easily read the LMS reports when publishing to SCORM 1.2.

Matthew BibbyMatthew Bibby

Have you ever looked at your LMS reports and gotten confused because you see something like this:

LMS report showing question as 'Scene1_Slide1_Essay_0_0.'

Unclear data makes it hard to know what question an answer relates to, slows you down when you are checking learners' responses and can be frustrating to deal with. You shouldn't have to create a spreadsheet containing details of what question maps to what interaction data label!

In this tutorial, we will look at an easy way to prepend our question data to the learner's response so that you are able to easily read the LMS reports.

Where Do We Start?

The first step involves building a basic quiz. In this example we will be using essay questions, as we need a quiz type that exposes the variable that the learner's response will be stored in.

Unfortunately, not all Storyline quiz types expose the variable that the learner's response will be stored in. For example, if we add a multiple choice question, there is no way to access the variable the answer uses.

However, there are ways to work around these limitations.

But for now, open Storyline and go to Insert > New Slide > Survey > Essay:

Insert Slides > Survey > Essay

You'll also need a result slide to send the data to the LMS. So go to Insert > New Slide > Blank Result Slide:

Insert Slides > Blank Result Slide

Our project will then have a text variable used to store the response. By default, assuming it is the first text entry box included in the course, the variable used will be TextEntry.

Let's change that to something that makes more sense...

Go to the Variables window by clicking on the Manage project variables button at the top of the Triggers panel:

Manage Project Variables

Then find the TextEntry variable and rename it Response01:

Variable

While the Variables window is open, let's also create a variable that can store our question data. Hit the plus icon in the bottom left to create the new variable and call this Question01.

Then add the question text to the value field:

New text variable called Question01 containing the value 'What's the most interesting fact you know?'

Now that we have those organised, let's dig into the cool stuff.

Let's Write Some Code

We are going to use JavaScript to prepend the question text to the learner’s response. This code should be executed before they leave the page where they entered the response. So that means that we need to have an Execute JavaScript trigger attached to the Submit button that runs before the Submit interaction trigger:

Execute JavaScript triggered when learner clicks the Submit button

Then open the trigger and click on the Script button:

Trigger wizard, action execute JavaScript, add/edit JavaScript button highlighted

Now let's add our JavaScript.

We will start by establishing communication with Storyline:

var player = GetPlayer();

Then we'll fetch our question text. Remember that this is stored in the Question01 variable:

var question = player.GetVar("Question01"); 

Now let's fetch the learner's response from the Response01 variable:

var response = player.GetVar("Response01");

Then we can combine those two variables into the one string:

var prepend = "(" + question + ") " + response;

And send that value back to Storyline. It needs to go back into the same variable it originally came from:

player.SetVar("Response01",prepend);

The response that is being reported to the LMS will now look something like:

LMS report showing that question data has been prepended to the response

As you can see above, the question is still listed as Scene1_Slide1_Essay_0.0.. However now that the question data has been added to the response, it's easy to see which question is being answered.

Here is that section of code again:

var player = GetPlayer();
var question = player.GetVar("Question01"); 
var response = player.GetVar("Response01");
var prepend = "(" + question + ") " + response;
player.SetVar("Response01",prepend);

Making Sure This Is Not Visible to the Learner

If we stopped here, then the learner may see that the question text has been added to their response on the off chance that they revisit that slide.
Note

Depending on how you build your question, this step may not be required. So before you add this script, test your project and see if the modified response is displayed to the learner when they revisit the question slide.

We don't want that.

So let's write some more code!

This JavaScript needs to go into an Execute JavaScript trigger that runs when the slide timeline starts:

Execute JavaScript when the timeline starts

Also, we will need to change the When revisiting option in the Slide properties to Reset to initial state to ensure this trigger runs if the learner revisits the slide.

We can do that by clicking the Properties button (the little gear icon) in the Slide Layers panel:

Properties button

Then we can change the When revisiting option to Reset to initial state:

When revisiting set to reset to initial state

Back to our code...

Once again, we want to establish communication with Storyline:

var player = GetPlayer();

Then grab our modified response:

var response = player.GetVar("Response01");

And check if the response includes the question text and if it does, remove that text and send the variable back to Storyline:

if (response.indexOf("(")=0){
    response = response.replace(/ *\([^)]*\) */, "");
    player.SetVar("Response01",response);
}

And that's all we need!

Here is that section of code again:

var player = GetPlayer();
var response = player.GetVar("Response01");
if (response.indexOf("(")=0){
    response = response.replace(/ *\([^)]*\) */, "");
    player.SetVar("Response01",response);
}

How Does This Work When I Have More Than One Question?

These triggers need to be added to each question slide. And you'll need to modify the code so that it refers to the correct variables. So, for example, if you have a second question in your course that uses the variables Question02 and Response02, the code should be changed to look like this:

Code block 1:

var player = GetPlayer();
var question = player.GetVar("Question02"); 
var response = player.GetVar("Response02");
var prepend = "(" + question + ") " + response;
player.SetVar("Response02",prepend);

Code block 2:

var player = GetPlayer();
var response = player.GetVar("Response02");
if (response.indexOf("(")=0){
    response = response.replace(/ *\([^)]*\) */, "");
    player.SetVar("Response02",response);
}

If you need to change this for heaps of questions it may be quicker to do so in your code editor rather than in the Storyline Execute JavaScript window.

If you don't have a preferred code editor, download Sublime Text and use that. But don't you dare try and do it in Microsoft Word. Here is an example that shows how quickly the code can be modified in Sublime Text:

Using find and replace in Sublime Text to update variable names

What About the Other Question Types?

This approach only works when the variable used to store the response is exposed. This means that some of the standard question types, such as multiple choice, will require further work in order to use this approach.

Personally, this is a non-issue for me, as I don't use the inbuilt question types for a number of reasons. Instead, I build the questions from scratch using a bunch of triggers and variables.

I do this because I appreciate having full control over the interaction and don't want to deal with the weird bugs that come with the inbuilt questions.

If you'd like to learn how to build these kinds of questions yourself, leave a comment below and I'll write about it in the future.

Demo

Here is a little demo that shows how the question text is prepended to the response:

Files you might need:

Here is the .story file that was used in this example.

Here is the published output that you can use to test this in your LMS.

Frequently Asked Questions:

Q. Why didn't you use that font you like so much in the text entry field and to show the modified response on the second slide?
A. Because fonts can't be embedded in the published output as noted here. That being said, if you are using SL360 there is a way that you can use fancy fonts with variable references.

Q. Are there any downsides of using this method?
A. Yes, there is one.

Q. Would you like to tell us what it is?
A. No, I'll leave it for you to discover. It'll be like an easter egg hunt.

Q. I don't like easter eggs. Can you please just tell me?
A. Okay, if I must. SCORM 1.2 can only store a limited amount of resume data, as noted here. As we are adding additional text to the response, that means that the resume data will also grow in size. Storyline is pretty good at compressing this resume data so hopefully this won't cause any issues for you, but it is important to be aware of the possibility.

Q. Does this work the same way in Storyline 360 and Storyline 3?
A. Yes.

Q. What about Storyline 1?
A. I think so, but I haven't tested it because, well, I don't want to.

Q. Does this work in HTML5? (i.e. will it work on my phone and tablet?)
A. Yes.

Q. Will this work in Articulate Mobile Player?
A. No. The Articulate Mobile Player doesn't support JavaScript, so this won't work. I don't think anyone uses the Articulate Mobile Player anyway.

Q. Do Articulate support this approach?
A. No, they don't provide support for custom JavaScript. So if you run into any issues leave a comment below (or contact me privately) and I'll help you.

Q. You didn't use the word silly once in this tutorial. I'm proud of you for being a little mature for once.
A. That's not a question. And thanks. I think.

Q. My question isn't listed here, what should I do?
A. Prepend it to the response you'd like to receive from me and then ask in the comments below.

If you found this tutorial helpful and think others in your network will also, please share using the share buttons below. Thanks!

Matthew Bibby
Author

Matthew Bibby

I'm Matt. I'm an eLearning Consultant. I help people like you develop memorable, engaging and profitable training programs. What do you need a hand with?

Comments