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
- JørgenNielsenCommunity Member
Hi Vince,
I placed your script on a button and showed the variable in a text field. It works OK in SCORM Cloud LMS. When you click the button, your student name shows up in the text field. I attach my example.
- PhilMayorSuper Hero
Have you set a text variable in Storyline called newName?
- tomwatsonCommunity Member
hey can you tell me about this LMS...
- 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.
- PhilMayorSuper Hero
Sorry I only checked it with Moodle it may be that your LMS does not support this
- LucioCommunity Member
Hi Phil,
I know this is old but other than the student's name, is there any other information that could be retrieved from Moodle such as number of attempts? Is there a list of api commands, i.e.: "getstudentname()", available somewhere?
Thanks
- PhilipLima1Community Member
Hi Lucio,
The only one I know if is student name.
Sorry I couldn't be of more help.
- 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.