Forum Discussion
lmsAPI Functionality in HTML5 Output
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!
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);