Forum Discussion
lmsAPI Functionality in HTML5 Output
Hey all,
I've been searching through the forums and haven't been able to find anything solid. I'm using Storyline 360, outputting to both HTML5 and Flash to cover my bases, since the audience doesn't have dedicated machines that they are taking this from.
I'm relying heavily on external Javascript that I wrote, which I have tested thoroughly in the Flash version, and it works fine. But when it comes to the HTML5 version, it stops working. I've proven that I'm able to get into the Javascript functions, like I would expect, but it appears that lmsAPI is no longer available to the course.
Are there any similar functions to those of the lmsAPI functions in the HTML5 output?
Specifically, I'm looking for a way to do the following in HTML5:
- Get the StudentID from the LMS.
- Get the StudentName from the LMS.
- Manually call SetStatus("completed"); to pass a completion to the LMS on the last page of the course.
- AdamTrosperCommunity Member
No problem! Try this:
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.SetReachedEnd(); - AdamTrosperCommunity Member
For #1 and #2, I originally thought the same thing. For example, you should just be able to call
lmsAPI.GetStudentID()
to get the Student ID. However, this wasn't working when launching from HTML5 for some reason.After lots of testing and guessing, I found a solution. Turns out the reason why it wasn't working was because lmsAPI wasn't actually set up as a variable like it is when you use the Flash version. (Still not sure why this is, honestly.) But, you can use the following line to get the same functionality from lmsAPI, providedyou are actually launching from an LMS:
var lmsAPI = parent;
I actually ended up creating a function for myself to use, to error-check a little bit:
function findLMSAPI(win) {
// look in this window
if (win.hasOwnProperty("GetStudentID")) return win;
// all done if no parent
else if (win.parent == win) return null;
// climb up to parent window & look there
else return findLMSAPI(win.parent);
}
function someOtherFunc(){
var lmsAPI = findLMSAPI(this);
if(lmsAPI != null){
//do stuff
}
}- SteveGCommunity Member
Just found this post and it helped me solve an issue I was having after stripping the Flash from a Storyline 2 published course.
Many thanks
- AdamTrosperCommunity Member
Hi Helene,
SetStatus("completed") only works with the Flash version because the HTML5 version doesn't end up using the lms.js file. So, you will have to bypass that function and directly call the function that the SetStatus function would have called... Try this:
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.SetReachedEnd(); - ChrisPimCommunity Member
OK so I tried this
---------------------
var player = GetPlayer();
function findLMSAPI(win) {
// look in this window
if (win.hasOwnProperty("GetStudentID")) return win;// all done if no parent
else if (win.parent == win) return null;// climb up to parent window & look there
else return findLMSAPI(win.parent);
}
var lmsAPI = findLMSAPI(this);
var myName = lmsAPI.GetStudentName();
var array = myName.split(',');
var newName = array[1] + ' ' + array[0];
player.SetVar("newName", newName);-----------------------------
And it works!
Thanks so much
Chris
- stephaniekalinkCommunity Member
Hi Chris, I try to do the same thing but I don't know where to define the variable newName...
i put a trigger to execute the js in the begining of my page
i put the variable in the list of variable and decide is a text variable
i put a text field il my page with the variable insidei published in html5
i have sl 360
and i tried in my lms and it doesn't work...could you help me ?
- AdamTrosperCommunity Member
Hi Amit,
I would try replacing all instances of
SetStatus("passed");
orSetStatus("failed");
with one of the following:lmsAPI.SetPassed();
or
lmsAPI.SetFailed();This should call the correct function directly.
- amityunger-53b6Community Member
It works GREAT!
Thanks a lot! :) - MariaErinAnneDoCommunity Member
Hi Adam,
I used a combination of your suggested codes:
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("Results_ScorePoints"), 27, 0);var passingScore = "23";
if (player.GetVar("Results_ScorePoints") >= passingScore)
{
lmsAPI.SetPassed();
} else {
lmsAPI.SetFailed();
}Our LMS (Workday) reads this perfectly if the learner has passed the quiz which is set at 23 points (85%). The completion status is reflecting as Completed and the lesson grade as Pass.
On the other hand, if the learner gets below 23 points, the lesson grade is properly reflecting as Fail but the completion status is showing up as In Progress.
If I add this code:
lmsAPI.SCORM_CallLMSSetValue("cmi.core.lesson_status", "completed");
the completion status is properly showing as Completed, but the lesson grade does not reflect the Fail status.
The LMS Reporting is set to Completed/Failed, and the output option is SCORM 1.2.
Thank you so much!
Anne
- AdamTrosperCommunity Member
I don't have much experience with Moodle, so I'm not sure what the problem would be. Are you publishing to SCORM or AICC? I've only tested my code with those tracking types.
The only other thing I could think of is that the lmsAPI is not the 'parent' object, but is instead up a parent level or two. That's when I would include the findLMSAPI function I wrote in the comment above instead, since it recursively looks up one level at a time, trying to find the lmsAPI. In which case, you would replace:
var lmsAPI = parent;
with:
var lmsAPI = findLMSAPI(this);
---
If this still isn't working, I would start using Developer Tools to determine the root of the problem.
Hi Stephanie,
Thanks for checking in. This is something that our team is still taking a look at. Those features and Javascript elements that were accessible in Storyline 2, changed in Storyline 3 and 360 as we entirely rewrote the player and it's behavior.
Those types of modifications have always been unsupported, but we do see the value in their use, so we're looking at how and why they fit the needs of Storyline 2 users and what options we could include in Storyline 3/360 to fix it going forward.
- AdamTrosperCommunity Member
Hi Ashley,
I understand that the modification of Javascript is not necessarily "supported" by Articulate. That makes total sense, since it's not on your team if one of us makes a mistake in our coding.
However, in most cases I've encountered related to this topic, I believe we are only modifying the code because of a lack of a feature that meets our needs within Storyline.
For example, this entire thread probably wouldn't be necessary if there was a trigger for "Mark Course Complete" within Storyline. In that case, I would be able to simply say "Mark the course complete when the timeline starts on Page 4.4" or something to that effect.
Since this feature would be built into Storyline, it would presumably work in both Flash and HTML5, and wouldn't require external Javascript.
Alternatively, it could also be solved if we were given a new option in Publish Settings > Tracking, for "Mark [Completed/Passed] when user reaches slide: [4.4]".
I hope this is helpful for your team in determining how best to approach the request.
- ShaneLeonardCommunity Member
Adam Trosper
...this entire thread probably wouldn't be necessary if there was a trigger for "Mark Course Complete" within Storyline. In that case, I would be able to simply say "Mark the course complete when the timeline starts on Page 4.4" or something to that effect.
Since this feature would be built into Storyline, it would presumably work in both Flash and HTML5, and wouldn't require external Javascript.
BUUUUMMMP!
Adam - much appreciated for your contribution to what is probably the Articulate Hack of the Year - which is a prestigious award considering how many hacks are required.
Speaking of hacks...
Articulate Staffers... has there been any progress on the above mentioned and extremely well articulated feature suggestions? Articulate 360 offers a few wonderful new features (closed captions!!), but to completely break the users' ability to effectively communicate with the LMS is simply madness! Madness I say!
You should add the above mentioned action triggers. It will take a few days for your skilled dev team to do, and will literally retain many paying customers. Ready? Go!
Meanwhile... I think I have the featured workaround working on my Moodle System thanks to Ad-rock's self-calling Javascript function, but I have yet one remaining thorn in my side.
I can't, for the life of me, change the cmi.core.lesson_status to anything other than Failed (SL360, HTML5, Moodle). I can set the score. I can get a li'l tick in the li'l "you did a thing" box in Moodle, but if I view the attempt details, it's cmi.core.lesson_status = failed.I dunno.
My JS snippet is:
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("percentage"), 100, 0);
if (player.GetVar("percentage") >= 70)
{
lmsAPI.SetReachedEnd();
}That last command, I've also tried:
a) lmsAPI.SCORM_CallLMSSetValue("cmi.core.lesson_status", "completed");
b) SetStatus("complete");
c) lmsAPI.SCORM_SetCompleted();Any ideas?
Shane Leonard
...this entire thread probably wouldn't be necessary if there was a trigger for "Mark Course Complete" within Storyline.
Hi folks,
Thanks for your feedback here. I wanted to confirm that a new 'Complete Course' Trigger is currently in Beta and is on track to be released in an upcoming Storyline 360 update.
As you'd expect, the new trigger gives you the flexibility to specify all sorts of custom completion criteria from inside Storyline, and sits alongside the slides viewed and results slide as a third way of tracking course completion with an LMS.
We'll keep you posted and let you know once the update is available for download.
- Simon
- AdamTrosperCommunity Member
Hi Shane,
Thank you for the kind words! My guess is that you might be using a "Passed/Failed" instead of a "Completed/Failed".
I would recommend trying to call the following instead:
lmsAPI.SetPassed();
If you are looking for the different options you should be able to use with lmsAPI, here is the switch statement in the lms.js code, which I used as the basis of the code I wrote:
switch (strStatus){
case "complete":
case "completed":
lmsAPI.SetReachedEnd();
break;
case "incomplete":
lmsAPI.ResetStatus();
break;
case "not attempted":
break;
case "failed":
lmsAPI.SetFailed();
break;
case "passed":
lmsAPI.SetPassed();
break;
}Good luck!
- DamienDuddyCommunity Member
Adam Trosper, you sir are a genius! I actually whooped when your suggestions worked, as I've been trying this for months without success and just happened across your post today!