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

211 Replies
Steve Flowers

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.

Steve Flowers

Haha, that's what I get for multi-tasking. Phil's example demonstrates it the rearrangement. lmsAPI.GetStudentName() and SCORM_GetStudentName() should return identical values.

var player = GetPlayer();

var myName  = lmsAPI.GetStudentName();

var array  = myName.split(',');

var newName = array[1] + '  ' + array[0];

player.SetVar("newName", newName);

Jørgen Nielsen

lmsAPI.GetStudentName() is working for me, but SCORM_GetStudentName() is not - why?

I'm looking for a way to read/write values to lesson_location in SCORM 1.2, but lmsAPI does not offer a method for that. SCORM_CallLMSGetValue and SCORM_CallLMSSetValue in SCORMFunctions.js would be perfect, but how do I call them from my javascript? Do I need a src-statement?

Brett Rockwood

Slightly off topic but I was wondering if you could use something similar to pull down a student's business unit or cost center. This would be really great in that you could then have the course automatically present the material that is applicable to a particular team.

I pretty limited in my LMS/SCORM knowledge; are there standard names like that that can be pulled down?

Steve Flowers

Hey, Brett - 

Unless someone's storing a value in the data model to bend in that type of info, this usually isn't exposed. 

http://scorm.com/wp-content/assets/scorm_ref_poster/RusticiSCORMPoster.pdf

I agree with you, though. There are many pieces of information that I think could be carried forward from the LMS to customize / adapt to the needs of the user. I think things like accessibility preferences would be VERY useful.

Jørgen Nielsen

Sorry, that I'm repeating my question, but I never got an answer:

lmsAPI.GetStudentName() is working for me, but SCORM_GetStudentName() is not - why?

I'm looking for a way to read/write values to lesson_location in SCORM 1.2, but lmsAPI does not offer a method for that. SCORM_CallLMSGetValue and SCORM_CallLMSSetValue in SCORMFunctions.js would be perfect, but how do I call them from my javascript?

Brett Rockwood

Can I revisit this topic again? Using Phil's JavaScript I can get the student's full name from the LMS no problem. But I'd like to just get the first name to put a little personalization into the training, e.g. "Hi Erika, welcome to today's session...". How would I need to modify the script to pull just the first name?

Here is the full name script:

var player = GetPlayer();

var myName = lmsAPI.GetStudentName();

var array = myName.split(',');

var newName = array[1] + ' ' + array[0];

player.SetVar("newName", newName);

//myName = player.GetVar('myName');

//player.SetVar("newName", newName);

Thanks as always.

Brett Rockwood

Andrew, that does it. Figured it was something simple like that. Now the only problem is the way names have been entered in our LMS. It looks like some people (me, for example) have their middle initial as part of their first name... [sigh]. Still, it is working and it's better than the whole name.

Thanks to you both.

Brett Rockwood

Hi Jenny,

Unfortunately, no. I don't know how you could separate out an initial if it was entered as part of a first name. My first thought was to see if there was some kind of script that could limit the name to just one word but quickly realized that, even if were possible, it would mess up a lot of people who have first names like Ellie May and Billie Jean...

Vince Pileggi

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?

Vince Pileggi

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.