Forum Discussion
lmsAPI Functionality in HTML5 Output
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])
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.
- JoeFrancis4 years agoCommunity 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.
- DerrickThomas4 years agoCommunity Member
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
- AdamTrosper4 years agoCommunity Member
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.- DerrickThomas4 years agoCommunity Member
Thank you, Adam.