Storyline - Set LMS Status with JavaScript

Jun 26, 2014

As known with previous Articulate products and versions, there are traditionally only two ways to set the LMS status to "complete".

  1. Number of slides viewed
  2. Score on quiz/test


A third "custom" way to set completion in the LMS:

  • Slide location


This third way would be more appropriate with multi-branching courses where the test is really landing on a particular screen or one of multiple screens.

Publishing

When publishing, choose the slide count method set to all slides. In a multi-branching course the learner would not see all slides but the course will be set to complete before the learner views all slides.

Flash method

In the past, this was accomplished with an imported flash file that would call a JavaScript function. That is still possible using the AS2 "setStatus.swf" file found attached to this post.

However, in Storyline, you can call JavaScript functions from any trigger, including a slide trigger.

JavaScript method

So here is the least bit of JS you need on a trigger to mark a course complete:


Run that little bit of code in a JavaScript trigger on any slide, object, button, etc. and Storyline will tell the LMS that the course is done.

Other options… "completed", "incomplete", "failed" and "passed"

Some LMSes want a bit more info. And you may want more yourself; like a score. That only takes a few more lines of code be added before we call SetStatus:


Now you can set the course status whenever/wherever you want.

72 Replies
Curtis Wiens

Hey Guys, I realize this is an old thread but I am having some trouble getting this to work when I publish for html5 only. I tried Scotts sample file on our LMS, because I thought I was doing something wrong, but it does not work either when I publish for only HTML5. If I publish for HTML5 and Flash SetStatus("completed") marks the course complete on Cornerstone. Any ideas?

Mateusz Szuter
Curtis Wiens

Hey Guys, I realize this is an old thread but I am having some trouble getting this to work when I publish for html5 only. I tried Scotts sample file on our LMS, because I thought I was doing something wrong, but it does not work either when I publish for only HTML5. If I publish for HTML5 and Flash SetStatus("completed") marks the course complete on Cornerstone. Any ideas?

Hey Curtis,

code for html5 is a bit different:

var player = GetPlayer();
function findLMSAPI(win) {
if (win.hasOwnProperty("GetStudentID")) return win;
else if (win.parent == win) return null;
else return findLMSAPI(win.parent);
}
var lmsAPI = findLMSAPI(this);
lmsAPI.SetScore(player.GetVar("Your_Score_Variable"), 100, 0);

Here's the optional code for setting passing threshold and thus completion status:

var passingScore = "75"; 
if (player.GetVar("Your_Score_Variable") >= passingScore)
{
SetStatus("passed");
} else {
SetStatus("failed");
}

However, I've seen some approachesu using different 'commands' for SetStatus, because sometimes it won't work. I've made a fast search and found this:

lmsAPI.SCORM_CallLMSSetValue("cmi.core.lesson_status", "completed");
You can change completed to passed or failed, depending on your needs.

lmsAPI.SetReachedEnd();
can do the trick also.

You must of course change "Your_Score_Variable" to name of your variable containing score :)

Sanduni Fernando

Hi Mateusz, 

Thanks a lot for looking into this. I am publishing for SCORM 1.2, HTML5 only. May be I am doing it in a wrong manner.

I am offering points based on question number. Questions are presented randomly. In order to remove the complexity I have prepared the attached file to show how I used the javascript. The published file (zip file) is also attached here. I want to pass some points to LMS without using the results slide.

I have uploaded this to SCORM could and tested but score does not reported there.

Do I have to add something to "GetStudentID" in the javascript?

 

Laurel Thomas

Hi, I'm trying to follow along with the JavaScript code, but I admit I'm not a programmer like that.

I'm using Storyline 3 and need to publish using AICC. I'm confused, though: am I still including a quiz slide and results slide, or does the JavaScript replace all that? 

I want to set a numeric variable in the course to equal the results score/points. The "Score" variable is already out of 100 -- it starts as 100% and the learners' selections take away points from the percentage. I need to send the score they end with and if it passed or failed. Anything below 96% is failing.

This is what I have so far:

var player=GetPlayer();
var customScore=player.GetVar("Score");

//get LMS API
var lmsAPI = parent;
//set score; the first number is the score
lmsAPI.SetScore(customScore, 100, 0);

Glen Savory

Hi all,  Been reading through this thread and still not clear what I need any help would be appreciated.

What i need is to have 2 buttons  One when clicked will place the course as Incomplete and One as complete

I dont need scores etc all im looking for is what Javascript i need to attach to a button. Im guessing this would do the job

SetStatus("Complete")

or SetStatus("Incomplete")

Or do i need more Javascript?   

Thanks

Carol Dawson

Hello! I'm so excited to find this thread because I think it could solve a problem a lot of users are having. I have several required courses with testouts. I'm thinking if I can put an action on the last page in Storyline (which they only reach by passing the testout), I could execute JavaScript to send completion to Cornerstone LMS. I would then import that into Rise and if someone passes the testout, they get completion and if they don't, they would need to continue to the end of the course, where they would then get credit.

I know almost nothing about writing JavaScript. I am currently using SCORM 2004, and am considering xAPI since I've not used it and would like to test it out. I would want to report the scores to the LMS.

Would someone be willing to share the JavaScript needed for both? I would greatly appreciate it and, if it works, I will add an update to the thread about not being able to set two different completions.

Anne DeFelice

I am having issues with this code only working intermittently. This just started today--might it have something to do with the new release yesterday? 

 

Also as a separate question, do I need to have this command? lmsAPI.SetScore(player.GetVar("points"), 100, 0); We do completion based on number of slides completed, which I assume is handled by SCORM_CallLMSSetValue("cmi.core.lesson_status", "completed")

 

Here is the JavaScript I am using

var player = GetPlayer();
function findLMSAPI(win) {
if (win.hasOwnProperty("GetStudentID")) return win;
else if (win.parent == win) return null;
else return findLMSAPI(win.parent);
}
var lmsAPI = findLMSAPI(this);
lmsAPI.SetScore(player.GetVar("points"), 100, 0);
SCORM_CallLMSSetValue("cmi.core.lesson_status", "completed")

 

 

 

One more question--do I need to use both of these lines, or just the second one? Is it necessary to set a score if the Completion is set by "slides viewed?" and anyway it is being forced to "completed?"

lmsAPI.SetScore(player.GetVar("points"), 100, 0);
SCORM_CallLMSSetValue("cmi.core.lesson_status", "completed")

 

 

Thanks,

Anne

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