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:

  1. Get the StudentID from the LMS.
  2. Get the StudentName from the LMS.
  3. Manually call SetStatus("completed"); to pass a completion to the LMS on the last page of the course.
146 Replies
Adam Trosper

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
}
}
Chris Pim

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

Adam Trosper

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.

Chris Pim

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

Adam Trosper

In the code you tried, did you include the function from my previous post?

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);
}
Chris Pim

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

Adam Trosper

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!

Akshay Rao

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

 

Alyssa Gomez

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. 

Adam Trosper

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:

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);

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.