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
- SteveFlowersCommunity Member
Hey, Andrew -
Should be able to grab the value through a JavaScript function. This won't work in HTML5 at the moment but should be fine in the Flash based version. Try this in a JavaScript trigger:
var player=GetPlayer();
player.SetVar("sLearnerName", SCORM_GetStudentName());
This'll grab the Student Name using the built in function in SCORMFunctions.js and push it into a variable called sLearnerName. If you need to arrange it differently you may need to split to an array and arrange the First / Last as separate parts before pushing in.
- OgbishBarrowCommunity Member
Hello please I need help on executing this. What is the simplest way to create a flow with this. E.g. Where do I insert the code, what should the next slide show and how do I create a display that will welcome the person
- JoshMasseyCommunity Member
Steve,
I doubt you pay any attention to this 7 years later - but I just had to say thanks! I have been racking my head against this keyboard for hours...all I needed was the SCORM_ component to work with the LMS we are using.
So excited!
- AndrewRostCommunity Member
That's because the student name is stored as first name last. Set the array[1] to get the first name.
- VincePileggi1Community Member
Hi all,
I am trying to pull information from the LMS and save into Storyline variables. To start off, I'm trying to grab the user's name. I used the Javascript code shown in this thread but it doesn't work for me.
var player = GetPlayer();
var myName = lmsAPI.GetStudentName();
var array = myName.split(',');
var newName = array[1] + ' ' + array[0];
player.SetVar("newName", newName);
Do I have to change something based on the particular LMS I'm using? What could be the problem?
- 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
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.
- TanmayGhoshCommunity Member
Hi,
I have been actually able to do that now in HTML5 too. I have used the same javascript code to fetch student name from LMS and current date.
The only difference is I have not used the code in the result slide where the certificate will appear. I have used the code at the very first slide of my course and stored them in Storyline variables. In the certificate popup in result slide, I have just used those 2 Storyline variables.
It worked in IOS 7 that I'm testing!
- AlexYong1Community Member
Hi Tanmay,
That's a pretty cool workaround, would you be willing to share a sample file of how you did that? Thanks a ton!
- TanmayGhoshCommunity Member
- CindyPandkeCommunity Member
Thanks everyone for sharing your expertise. It is real helpful to newbies...
We are using Storyline 2 , our LMS is Saba 7.2. The code provided in this thread works great but for only the first time a course is published and uploaded to our LMS. If the file needs to be modified or changed and published a second time then the field (username and/or newName) returns a blank.
Has anyone else experienced this? Is there a known fix that you can share?
Not sure what other information you need to be able to assist. Please let me know and I will do my best to supply it.
- MarkCairnsCommunity Member
Hi Stephanie,
I've added the missing variable and tested it in Scorm Cloud. It works now. See attached.
Hi Eduardo,
This forum discussion is a bit older and as such I'm not sure that folks are still subscribed. You may want to reach out to them directly using the "contact me" button on their profiles.