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
jeff barclay

I know this is old but I’ve searched everywhere to try and find how to get the same variables already stored in player() (flash version) while I’m only using story_html5.html

I have random quiz questions and need to capture the wrong answers selected as well as the randomizes question asked?

the g_quizzes produced all this in flash player, now how can I gat the same in html5...

Alexa Yacteen

Hi Matthew,

I noticed you have helped a lot of people with this similar issue and I am hoping you can help me figure out what is wrong with my code:

......

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

....

This originally worked when publishing to SCORM 1.2, but now that we are publishing to SCORM 2004 4th edition, the name populates with "undefined" in front of the name once the course is uploaded on the LMS.

One thing to note is this is not happening when testing on SCORM cloud site.

I've seen posts saying to change ' var myName = lmsAPI.GetStudentName (); ' to '   var myname = lmsAPI.SCORM2004_GetStudentName(); ' but I don't know if i need to keep the ' var newName = array[1] + ' ' + array[0]; ' line. I am assuming the [0] or [1] is reporting the undefined, but the client wants the full name (first and last) of the learner to be generated on the certificate.

I really appreciate any help with this! Thank you

Adam Trosper

To clarify your question, when you use the lmsAPI.SCORM2004_GetStudentName(), you are getting something like "undefinedJohn Smith"?

What GetStudentName (and the 2004 version) both send back is a string of the student/learner's name but in this form: "Smith, John".  The part of the code that's splitting string, and the resulting array, is to swap the order into FirstName LastName order (John Smith). 

So, array[1] should be "John"... and array[0] should be "Smith".  One of these might be coming back as undefined.

All of this is to say that it's possible that it's just the user in question simply doesn't have a first name or last name in the LMS.  But other users in the system still might, so you will need to account for both cases, if possible.

Some code you could use to possibly fix it is:

var newName = "";
if(array[1] != "undefined"){ newName += array[1]; }
if(array[0] != "undefined"){ newName += " " + array[0]; }

I hope this helps!

Alexa Yacteen

Hi Adam, I am getting "undefined John Smith"

When this code was used in the SCORM 1.2 output, the name was correct and there was no "undefined" for the certificate.  

To clarify, I haven't sent an updated version of the course for upload to the LMS yet. In that next version, I replaced this line of code: var myName = lmsAPI.GetStudentName(); with var myName = lmsAPI.SCORM2004_GetStudentName()

I was hoping to gain some insight into whether or not any other parts of the code need to be adjusted. Unfortunately, I'm unable to test the course myself on the LMS, so I am hoping to get the code right before sending in my next version before course deployment. SCORM cloud is not having any issues with the original code in the published SCORM 2004 output. 

I wonder if the code mentioned in a post above would work? :

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);
var name = lmsAPI.SCORM2004_GetStudentName();
var nameArray = name.split(', ');
var firstName = nameArray[1];
var lastName = nameArray[0];
var fullName = firstName + ' ' + lastName;
var player = GetPlayer();
player.SetVar("Name",fullName); 
Adam Trosper

Hi Alexa,

This sounds like it might be an issue with the LMS -- specifically, the way the user's first name and last name are being stored.  I would check those fields out in the LMS itself, and see if you see something obvious (like the first name being blank, and the last name being "John Smith"). 

If this isn't the case, I would check with your LMS provider to see if they are mapping the fields correctly. 

Typically, if something is working correctly in SCORM Cloud, but isn't working correctly in a specific LMS, it usually points to something being incorrect in the LMS itself. 

Derrick Thomas

Hi everyone,

I am trying to pull the username from Canvas for a storyline 360 certificate but I'm having a bunch of trouble.

I am using javascript but cannot seem to get it right. Here is what I have in my script:

var name = lmsAPI.GetStudentName();
var nameArray = name.split(", ");
var firstName = nameArray[1];
var lastName = nameArray[0];
var player = GetPlayer();
player.SetVar('first_name',firstName);
player.SetVar('last_name',lastName);

then I print the name using 

%firstName”%
%lastName%

Any help will be appreciated.

 

Thanks

Joseph Francis

While the SCORM standard for cmi.core.student_name is last name, first name and middle initial  (last name and first name separated by a comma), I discovered the LMS I am working with (Absorb) is using FirstName LastName (with a space, no comma, between) to store the student's official name. So, trapping for the comma is throwing the function off. I adjusted my code accordingly, by trapping for the space and assigning index 0 to First Name (instead of Last Name):

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

var lmsStudent_Name = lmsAPI.GetStudentName();
     var nameArray = lmsStudent_Name.split(" ")

     player.SetVar("strFirstName",nameArray[0]);
     player.SetVar("strLastName",nameArray[1])

Adam Trosper

Hi Joseph - Good call on this.  The only thing you will want to be careful of/double-check, is how it will behave if someone does have a middle name/initial in there.   You should be safe if you change the last line to this:

player.SetVar("strLastName",nameArray[nameArray-1]);

This will make it pull the LAST item of the nameArray, no matter how long the array is.

Joseph Francis

That goes back to the rules your organization has in place for data, in this case, the user name. If the rule is a middle initial is required, it has to be across the board. It can't be there occasionally and absent occasionally. In many organizations, there's some integration going on in the LMS with the people system or mail system (Microsoft Exchange, for example) which enforces business rules for userName and other data points.

Otherwise, it ends up being Garbage in => Garbage Out.

Derrick Thomas

Thanks for your help, I got it to work, however, I am getting a comma at
the end of the last name so it displays as Firstname Lastname,

Also, I would like to pull the email address from Canvas and send the
certificate to the email, any help with this would be greatly appreciated.

Thanks

Adam Trosper

Hi Derrick -  you can only get certain information from the LMS at runtime, and email address isn't one of those fields.  Some LMSes happen to use the email address at the Student ID, but most use a separate field for Student ID (login id) and Email Address.  You could try using the lmsAPI.GetStudentID(); function to see what you get back from the LMS.

For your question about the extra comma appearing after the last name, it's really hard to say what's going on without guessing.  It sounds like the .split() function is set up one way, but the student_name string returned from the LMS is formatted differently than what you were expecting.  I recommend looking at exactly what you are getting back from the LMS when you call lmsAPI.GetStudentName(); and then tweaking your JavaScript code from there.  

Joseph Francis

Unfortunately, neither SCORM 1.2 nor SCORM 2004 has an equivalent data element to the AICC Course.ID data element.

As for a Web Object loading a page with a studentID as a query string name/value pair, what you're after is something which is loaded dynamically at run-time, which isn't quite what a Web Object is. Whether it's an index.htm page on your local machine or an external URL, the location is fixed once you publish the course.

Hila Vauch

Thanks @Joseph for your quick reply! Yes, you described it well as this is exactly my problem - i'm trying to create a web object with dynamic parameters (the link I use inside the web object is to an external system and i'm trying to send it parameters related to the course the user came from).

Do you have any idea how I can achieve that? what is AICC Course.ID data element? i'm not familiar with it - would it be possible to convert my SCROM files to AICC? if it has dynamic parameters related to the LMS course maybe I should try it?


Adam Trosper

Hey Hila! 

It sounds to me like you are trying to do something that is better reserved for calls outside of the courseware itself (perhaps calls/reports that should be happening from the LMS instead).  Without knowing exactly what you are trying to accomplish, what data schema the external system is expecting, etc., etc., etc., it's hard to know where to even start.  

I think if I were in your shoes, I would contact someone at the external system and see what data/parameters they are even looking for, and in what format they need it sent.  I would recommend reaching out to them to get more info on what they are expecting, and maybe ask them if they have a preference between AICC, SCORM 1.2, SCORM 2004, or something else entirely.  They should be able to help you determine the best approach that you should take.

In terms of converting between SCORM 1.2, SCORM 2004, AICC... I'm assuming you are doing this in Storyline, since you are on a Storyline forum.  It should be a simple change in the Publish settings (LMS tab).

Hila Vauch

Thanks again for replying so fast :)
well- I am the external system! basically the whole flow is that the user starts inside the LMS, taking a course (currently built from SCORM files), then from within the SCORM I'm sending him to my system with a link - implemented inside a web object.
I've contacted my LMS provider and it's not possible sending parameters from within the LMS (I literally tried every learning material possible) so I was thinking maybe sending parameters as urlParams from inside the SCORM (for example course id, learning object id, user id and such) so I can recognise who the user is (on my external system) and which course he came from (the LMS).

Now, having said all that (hoping you're still here Adam) - I ran into your post noting AICC Course.ID - Is that referring to the LMS course? can the AICC hold parameters? 
hope my question makes more sense now... 

Adam Trosper

Hi Hila,

I think it's on an LMS-by-LMS basis exactly what information is provided to the course at runtime.  A lot of these fields are optional.

I think my advice would be to change the tracking type to AICC, export it and upload it to your LMS to test it out.  You should be able to turn on Debug Mode, and test what will and won't be possible.

There are 2 ways to turn debug mode on:

  1. In scormdriver.js, change:
    var SHOW_DEBUG_ON_LAUNCH = true;
  2. Using Dev Tools, you can call ShowDebugWindow()
Onno Bakker

Hi Matthew,

Thanks for your code:

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);
var name = lmsAPI.SCORM2004_GetStudentName();
var nameArray = name.split(', ');
var firstName = nameArray[1];
var lastName = nameArray[0];
var fullName = firstName + ' ' + lastName;
var player = GetPlayer();
player.SetVar("Name",fullName); 
  • Works like a charm!

 

I would also love to GET the users Email from the LMS and SET this as a variable in SL. Is this possible? If so how?

 

Kind regards

 

Joseph Francis

A learner's email address isn't part of the SCORM 1.2 or 2004 data model.

SCORM Run-Time Reference Guide

If your LMS uses the learner's email address as the student ID (cmi.core.student_id / cmi.learner_id), you would be able to pull that. But the last few enterprise LMS' I've been on either use the Employee ID or the next available ID in the database as the Student ID.

Robert Webbe

Found this topic via search and found out that it's only working when pusblished in SCORM.

Now a days we publish everything in xAPI and then this code is not working. Can't figure it out, my javascript knowledge is not sufficient. Does anyone knows a solution for this?

Besides the name, I like to retrieve information from our (LearningLocker) LRS and use it as a variable. Cannot find anything about this too. It seems to be black magic..,