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
What's above used to work. Last line needs to me modified if using Storyline 3.10 (and likely in later versions too) becasue SetStatus is no longer defined.
var lmsAPI = parent;
lmsAPI.SetScore(100, 100, 0);
lmsAPI.SetPassed();
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:
Here's the optional code for setting passing threshold and thus completion status:
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 :)
Thanks Mateusz for sharing that code here!
Great thanks! I am going to test this today.
Hi Curtis,
Did this work for you? I am also having the same issue. I tried with the new code that Mateusz provided, but no luck!
Hi Sanduni,
Hopefully, Curtis is still subscribed here, but you are certainly welcome to reach out to the user directly via the 'Contact Me' option on the user profile if you do not hear back soon.
Thanks Leslie.
H Sanduni,
the second part is for scorm 1.2, are you using it?
i can post tomorrow similiar code parts for scorm2004 if you need
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?
Hey Sanduni,
Reported points must be in range from 0 to 100, or simplier - passed in percents.
So when you have 2500 to achieve, that's not correct value for scorm :) you must calcuate it to the percents and then send it to the scorm.
Just change your points from 1000 to 10 and it will work in attached case.
I changed the points and it worked like a charm. :)
Thanks a lot Mateusz. You are a star.
Nice job, Mateusz! I'm glad you were able to help Sanduni. 🌟
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);
Can we make the status as "started"?
You can set it to any value you want. The value is sent back to your LMS, the question is whether they will accept “started” or reject it. Ask your LMS provider what values they will accept.
This post was removed by the author
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
Hi Glen,
you need more javascript to do that ;) But first of all, you should publish to html5 and the second question is do you use SCORM 1.2 or SCORM 2004?
Thanks Mateusz, I do publish to HTML5 and use Scorm 1.2, also use Storyline 2 not 3 or 360
Hi Mateusz,
I know it is quite old, but I would really like if you could send the code part for Scorm2004 :)
Thanks
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.
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
Hello Anne,
you don't need the score obviously. ;)
Also, if you set completion based on slides viewed, why even bother with using javascript? Just use built-in storyline completion. It's far more reliable than meddling with javascript.
Thanks—we use it as a workaround for the LMS administrator only—if they need to manually set completion for some reason.
Get Outlook for iOS
This discussion is closed. You can start a new discussion or contact Articulate Support.