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.
- philMekCommunity Member
Hello everybody,
I read every single message in this thread , also here :(https://community.articulate.com/discussions/retrieve-lms-user-name-as-variable) , and in some others (https://community.articulate.com/discussions/getting-the-student-name-from-the-lms).... (https://community.articulate.com/discussions/getting-student-name-from-the-lms-and-using-it-in-articulate)
But couldn't find what I am looking for :
My client LMS (Talentsoft) in SCORM 2004, can display cmi.learner_name as a variable.
I tried many many many syntaxes to grab this data, but I guess the only working one wasn't in my scope !
Can anymone help me ? what is the syntax to grab this value ?
thank you for the help
Philippe
- philMekCommunity Member
Bravo Matthew !
it works !
Thank you very much.
I changed a few things, as I only need (at this time) the firstname.
Also, my LMS return no space after the comma in studentname().
Here is your code with small modificaitons :
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",firstName);Do you know why in specification it is said : "cmi.learner_name", and in getting the value : GetStudentName() ?
I am not dying for the answer, just curiosity.
Anyway, you saved me, Talensoft support was unable to answer.
Have a nice day
Philippe
- jeffbarclayCommunity Member
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...
- AlexaYacteenCommunity Member
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
- AdamTrosperCommunity Member
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!
- AlexaYacteenCommunity Member
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);
- AlexaYacteenCommunity Member
Unfortunately, the above code is still returning "undefined" before the learner's first and last name.
- AdamTrosperCommunity Member
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.
- DerrickThomasCommunity Member
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
- JoeFrancisCommunity Member
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])
- AdamTrosperCommunity Member
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.
- JoeFrancisCommunity Member
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.
- HilaBenBaruchCommunity Member
Hey! would it be possible to get the student ID (with lmsAPI.GetStudentID()) and then implement that ID inside a web object as url parameter?
also - would it be possible to get through lmsAPI the course id?- JoeFrancisCommunity Member
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.