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".
- Number of slides viewed
- 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:
SetStatus("completed")
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:
//get LMS API var lmsAPI = parent; //set score; the first number is the score lmsAPI.SetScore(90, 100, 0); //set status; possible values: "completed","incomplete", "failed", "passed" SetStatus("completed")
Now you can set the course status whenever/wherever you want.
72 Replies
Hi HT.
Take a look at your SetStatus again. There are a couple of annoying "curly quotes" in there
”
Once I replaced them with standard quotes " it worked.
Thanks Tim for your help, even after taking out he curly quotes it still didn't work.
I finally managed to figure out that LMS is being unforgiving,and I had to set the score before I can change the status to" complete". Here is the final code in case any one else runs into this issue.
alert("you just clicked the button");
//get LMS API
var lmsAPI = parent;
//set score;
lmsAPI.SetScore(90, 100, 0);
//set status;
SetStatus("completed");
This post was removed by the author
Hi Scott, I found this thread and thought I'd take a chance that you get this question.
I'm trying to send a completion and score to the LMS using the above code. This is my code which triggers on the 2sec mark of the timeline. My variable for the users score is %Results37.ScorePoints%, the max score for the course is 2000 and the min score is 0. When I place this on the results slide (last slide), the initial part of my course stalls and the course/quiz won't work.
First will this code work, and second why is it stalling my course?
var lmsAPI = parent;
lmsAPI.SetScore(%Results37.ScorePoints%, 2000, 0);
SetStatus("completed")
I've just done it successfully using the following code as an "Execute JavaScript" Action When "Timeline Starts". It works on a button as well if you want it to.
In SetScore the 1st parameter, 99, is the score stored in the LMS. Take care that different LMS use different strings for the complete status. CSOD uses "completed" and it must be lower case, but other LMS may use other strings.
Hello
I have a course that contain a series of questions and other content slides. The requirement for the course is to have the user answer ALL questions, it doesn't matter if the user fail or pass the questions.. So what i did, was to set up the code for the JavaScript on the submit button of the last question. That way, my idea was that, when the user click, it will prompt the completion of the module in the LMS. But it doesn't seem to force the module to show completed.
I used the following code in the Execute JavaScript trigger for the submit button and it doesn't work. Any help or idea? Do i have to set up the completion settings of my course a certain way?
SetStatus("completed")
I know i could set the course to be completed once the user view a minimum of slides, but the courses have side slides and that would mix thing up. Would be way easier if we could just say, once the user have seen that slide the course can be completed.
I think you are missing the ; behind the code
SetStatus("completed");
my variable that is the results for my quiz is %Results37.ScorePoints%. The max points for the course is 2000. I have set this JavaScript to trigger on the final slide to push the score to the LMS. The script causes my course to stall about 8 slides in. The course stalls on the first slide of the course that has a JavaScript randomization script running. Why would this script (below) on the final side of the course, stall the 8th slide in the course just because it is also running a js?
/*Get player to reference*/
var player = GetPlayer();
/*get LMS API*/
var lmsAPI = parent;
/*set score; the first number is the score*/
lmsAPI.SetScore(player.GetVar("Results37.ScorePoints", 2000, 0);
Just a foot note here. This will only work for SCORM 1.2. SetStatus is not a function of SCORM 2004 and therefore you need to call SCORM2004_SetCompleted() if you are using 2004.
Hey there Jonathan! I noticed your comment got posted twice, so I wanted to let you know that I popped in to remove the duplicate. Thank you for chiming in to assist!
Hmm..that's not good. I am no JavaScript expert, just pulling things from chat boards. I need the code for TinCan. Anyone have that?
Hi JP,
You may want to message a few of the individual users on this forum discussion or others that you find about Javascript to see if they're able to offer help and advice, as the Javascript code or information isn't something that our team can assist with.
This post was removed by the author
Hi Everyone! I'm super new to Storyline 2 - am a power user in Lectora, so I get what I want to do and have been following this thread for some guidance. In Lecotra, having completion run on a page is pretty standard...
So I'm struggling with these settings and the javascript. I have a mini-branching scenario course - there are remediation tracks that are not required unless you score below a certain score (custom variables (number) that add with user clicks).
I cannot get the course to complete with the javascript that was posted by a previous user...I also have the course set to complete on the maximum number of slides, which believe was in the root post...
//get LMS API
var lmsAPI = parent;
//set score; the first number is the score
lmsAPI.SetScore(90, 100, 0);
//set status; possible values: "completed","incomplete", "failed", "passed"
SetStatus("completed");
Have I missed something? HELP PLEASE!! Thanks so much everyone :)
Hi Meghan
your post above says its a branching module with some slides not required...this could be the issue. If you set to max slides the user has to touch all slides, try setting to the number of slides every user has to touch without remediation tracks.
I would also test your file in Scormcloud to see if it completes successfully - if it does you may find it is a setting in your LMS that needs tweaking.
Thank you so much for the suggestion, Wendy!
It looks like everything was set up correctly, but there is a little bit of latency when the JavaScript runs in CSOD. I moved the trigger to timeline start so that there was a little more "time" to let the script run, instead of placing it at the root level of the triggers on the exit button.
Thanks again!
I have JavaScript set up that calculates the score and sends it to the LMS, and it does that successfully, but it does not mark the course as complete in SCORM Cloud when the passing score is achieved. I'm not using the Results slide tracking. Here's the JavaScript:
var p = GetPlayer();
var cs = p.GetVar("CurrentScore");
var currentScorePercent = p.GetVar("CurrentScorePercent");
var passScorePercent = p.GetVar("PassScorePercent");
var ns = 5; // Number of Question Slides
var currentScorePercent = Math.round(cs / ns * 10);
p.SetVar("CurrentScorePercent", currentScorePercent );
console.log("Current Score Percent " + currentScorePercent);
lmsAPI.SCORM_SetScore(currentScorePercent, passScorePercent, 0);
console.log("Score Saved");
In the Reporting options, I have "Report status to LMS as:" set to Completed/Incomplete.
I'm thinking I can add the SetStatus("completed"); to the end of the JavaScript but it should be only on the condition that the learner get 80% or higher. Any ideas?
Hi Ed,
regardless of whether the user gets 80% or higher shouldn't 'completed' still display. They have completed the course but failed instead of passing?
Hi Ed,
Are you using Storyline 360 and HTML5? This is something we've got our team looking into right now, so I'll be sure this forum discussion is linked for an update.
Hi Wendy - No, I was using the 80% or higher as the criteria for passing the module. If they got less than 80%, they would get the status of Incomplete (according to the Storyline Reporting options). That's what I was shooting for.
Attached is how SCORM Cloud is interpreting it.
SCORM standards have 2 separate settings: score is simply the score, status is whether they have passed/failed/completed/incomplete (which actual strings depend on your LMS).
So your code needs to say something like:
if (currentScorePercent > passScorePercent)
{
SetStatus("completed");
console.log("Pass"); }
else {
SetStatus("incomplete");
console.log("Fail");
}
Check with your LMS what strings you can use for Status.
Thanks, Colin. We publish to at least 2 different LMSs on a regular basis, and sometimes send our published files to customers if they can't use our default LMS. So checking LMSs for acceptable strings may not be easy.
If you don't use the SetStatus command, do you know if the LMS then uses the "Track number of slides viewed" number? I understand I need to use this option if I'm using JavaScript to send the score, instead of using the "Track using quiz result" option.
The only thing holding me back from making the course available to customers is this issue....I'm thinking that instead of branching and going the JavaScript route, I may just produce 2 courses and use the results slide. Less developing, testing, debugging, etc.
Hi Jonathan,
Ar you just putting "SCORM2004_SetCompleted()" in the javascript command or is there additional text? I have tried this to created a single course adaptive assessment which has six multiple results slides and can't get that to work in SCORM 2004.
Thanks
Hello,
I have one results slide, which calculates the 7 numeric questions I have. I use the results slide, so I can have a detailed view on the answers inside Moodle, because every single one of them will register.
However, numeric question can be graded 0 or 1, so when someone answers, he/she will get 1 point for every question at all. So, in the end, my results slide will always say, that the score is 100, because every answer is proper. I just need to know what the answer exactly was.
And then, I have little javascript and variables combo that calcualtes the proper ending result, which I would like to report the my Moodle. I've tried to override that score with SetScore and it works (I can see in that funny TOCC or whatever it is called. After result slide I have (100), and after javascript(80) for example).
But when I click "exit course" button it resets the final score back to 100 :(
Do you know maybe why or how I can overcome this
This discussion is closed. You can start a new discussion or contact Articulate Support.