Forum Discussion
Retrieve LMS User Name as Variable
I know you can have a user fill in a text box with their name and then later use that variable for personalization. What we would like to do is programmatically retrieve the user name from the LMS. Is there a way to set a variable with data from the LMS when the course is loaded instead of having the user enter their name?
Thx
- VincePileggi1Community Member
I tried the file attached from Jorgen and I still cannot get it to work. When I click the button that should get the student name, the text reference field goes blank. The LMS I am using is called LearnFlex and I am publishing to SCORM 1.2 if that makes any difference as well.
I appreciate the help everyone.
- SteveFlowersCommunity Member
Hi, Vince -
You can try a couple of things to troubleshoot the issue.
1)
alert(lmsAPI.GetStudentName());If your student name returns in the alert, the method is working and there's another problem. If it doesn't, try this:
2)
var lmsAPI = parent;alert(lmsAPI.GetStudentName());
It could be that your LMSAPI is nested in a parent. This jacks up the reference. If #2 returns your student name, let us know and we'll recommend a change to the original script.
- VincePileggi1Community Member
Neither of the above suggestions seem to be working. They both return blanks. It may be the case that this feature is not supported by the LMS. Any other suggestions?
Thanks again.
- JørgenNielsenCommunity Member
Student name is a mandatory Scorm data element, so the lms has to support it. I suggest, that you call the Scorm methods for getting the last error.
- VincePileggi1Community Member
I'm not sure if I did it correctly, but when I call the function lmsAPI.GetLastError() it returns 0. Still, it is not pulling the student name though...just a blank.
- VincePileggi1Community Member
Does anyone have more sugesstions to try? The fact that it is returning a blank( ie. " , ") it seems the code is working fine, but it is not grabbing the name properly from the LMS. Is it possible that the LMSAPI is nested in more than 1 parent? I initially felt good about this code:
var lmsAPI = parent;
alert(lmsAPI.GetStudentName());
But when that didn't work, I thought maybe the idea of nested parents could be taken further. Stop me if I don't know what I'm talking about here, just trying to get this to work somehow.
- JørgenNielsenCommunity Member
When the error code is 0 (no error) and the LMS in fact returns something (the ","), your call to the API is working. Are you sure, that the LMS ever registered a not-empty name for the user? You can check, if the user has a real name in the LMS user interface.
- VincePileggi1Community Member
In the LMS user interface, the student's name is visible at the top of the page when they log in. Also, they are able to generate certificates for courses and those contain their name as well.
- AndrewRostCommunity Member
You're testing this in Flash, correct?
- VincePileggi1Community Member
Correct.