lmsAPI Functionality in HTML5 Output
Apr 28, 2017
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.
145 Replies
For #1 and #2 - I thought those are system variables built into Storyline - so no javascript is needed - but I could be wrong.
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:
Hi,
I am using Moodle and Storyline 360
I have this code which works for Flash - get username. This populates a field in Storyline with variable %newName%
-----------------------
var player = GetPlayer();
var myName = lmsAPI.GetStudentName();
var array = myName.split(',');
var newName = array[1] + ' ' + array[0];
player.SetVar("newName", newName);
--------------------------------
It used to work in Storlyine 2 for HTML5 but does not anymore with Storyline 360
How would I use your workaround with var lmsAPI = parent;
...in my code above so it works in HTML5 and Flash on Moodle?
Any help greatly appreciated.
Chris
I would try updating it like this:
This is going to work 99% of the time.
OK I tried this...
var player = GetPlayer();
var lmsAPI = parent;
var myName = lmsAPI.GetStudentName();
var array = myName.split(',');
var newName = array[1] + ' ' + array[0];
player.SetVar("newName", newName);
With no success in Moodle. Any suggestions?
Chris
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.
Yes SCORM 1.2 HTML ouitput only
I tried:
-------------------
var player = GetPlayer();
var lmsAPI = findLMSAPI(this);
var myName = lmsAPI.GetStudentName();
var array = myName.split(',');
var newName = array[1] + ' ' + array[0];
player.SetVar("newName", newName);
---------
Sadly still not working. Thanks for trying.
I know nothing abot Moodle really. What would I need to ask my Moodle developers to check and find out? This would be very helpful for the next step.
Chris
In the code you tried, did you include the function from my previous post?
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
Glad to hear that works! No problem!
I just realized that I never got an answer to #3 on my list:
In HTML5, how can I manually call SetStatus("completed"); to pass a completion to the LMS on the last page of the course.
It currently fails, saying that "SetStatus is not defined."
Hi Matthew,
Will this completion code work with amount of screens viewed tracking?
Ofcourse, sorry Matthew. First day back from holiday today. Jet lag and Storyline variables/JS just don't work well together.
Thanks again.
HI Matthew,
That would definitely do the trick! I actually found another solution that works for HTML5 right now, but certainly isn't as direct as manually setting the lesson_status.
Hmm, Matthew, the code you provided doesn't seem to be working in HTML with our Moodle LMS. Should it?
Adam/Matthew, if I had a trigger for both codes you've provided, would that cause any issues? I will try your code now Adam, see if that works with HTML.
Thanks
James - My guess is that the variable lmsAPI isn't equal to parent, but rather parent.parent, or something like that. If you use the findLMSAPI function (as I helped Chris with earlier in this thread), that might work. I don't personally work with Moodle, but Chris was having a similar problem with Moodle.
Let us know if that works!
Thanks Adam. Apologies but I'm not totally clued up with JS so you may as well have been talking Chinese to me there.
Not sure what you mean, or how to type it out..
Thanks
No problem! Try this:
Adam - you're a saint!!! Perfect. Thank you so much.
If the module is using flash, will this still work?
Thanks again and for the fast replies!
Good question. I think it works for both, but I would test it just to make sure.
Thank you, thank you, thank you Adam! Oh the joy as seeing that word 'Complete' in Moodle after days of doubting my sanity.
Glad I could help! :) (I know the feeling, by the way!)
Hi we have upgraded from stroyline 2 to 360, our javascript progress tracking was working fine in storyline 2 but it is not working in storyline 360 in LMS
var slideName="slide1"; //Change here
var slideNo="1"; //Change here
var totalSlideNo="3"; //Change here
var previousSlide=lmsAPI.GetBookmark();
if(previousSlide.length <1)
{
var txt= slideNo+","+totalSlideNo+","+slideName;
lmsAPI.SetBookmark( txt);
lmsAPI.SetProgressMeasure(slideNo/totalSlideNo);
}
else if(slideNo==totalSlideNo){
var array = previousSlide.split(',');
var index = array.indexOf(slideName) ;
var snoindex = array.indexOf(slideNo) ;
array[0]=totalSlideNo;
array[1]=totalSlideNo;
var prevString=array.toString();
if(index==-1)
{
var txt=prevString+","+slideName;
lmsAPI.SetBookmark( txt);
lmsAPI.SetProgressMeasure(array[0]/totalSlideNo);
}
}
else{
var array = previousSlide.split(',');
var index = array.indexOf(slideName) ;
var snoindex = array.indexOf(slideNo) ;
if(snoindex==-1)
{
var _num=Number(array[0])+1;
array[0]=_num.toString();
}
else
{
}
array[1]=totalSlideNo;
var prevString=array.toString();
if(index==-1)
{
var txt=prevString+","+slideName;
lmsAPI.SetBookmark( txt);
lmsAPI.SetProgressMeasure(array[0]/totalSlideNo);
}
}
can anybody please help
Thank you in advance
Hi there Akshay,
Sorry you've run into this! We're working through an issue where the Javascript code to send completion status to LMS no longer works in Storyline 360. I'll let the team know about you experience, and I'll be sure to post an update here as soon as I get new information.
Thanks so much for letting us know what's going on, and I'm sorry if this is slowing you down.
In the meantime, you should be able to use the function that I posted earlier in this thread to access lmsAPI correctly. So somewhere at the top of your code, add the following:
If it doesn't work past that point, I'm not sure what the fix would be. I had to do a lot of workarounds with the combination between SL360 specifically and HTML5 that used to work fine in SL2.