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

Ah. The very first one posted was Flash only. However, HTML5 output supports the second one posted no problem. Has for awhile:)

Only works in Flash:

player.SetVar("sLearnerName", SCORM_GetStudentName());

 

Works in all:

var player = GetPlayer();
//might need to use lmsAPI=parent; on some LMS
var myName  = lmsAPI.GetStudentName();
var array  = myName.split(',');
var newName = array[1] + '  ' + array[0];
player.SetVar("newName", newName);
Alex Y

Gah!  Ok, but the issue that Tanmay found was that this JS wouldn't work on the certificate or results slide.  But now that i'm comparing the code I see he's using something different.  The code you posted above will work in the results slide too?  Or is that the limitation that Tanmay was working around? 

Thanks in advanced for helping me understand, this is so very helpful!

Steve Flowers

It works everywhere I've tried it. Yes, it should work.

However, since triggers work in order but JS runs asynch, If you're doing something that relies on the setting of the variable, you'll want to be sure you load in the name from the LMS with a bit of time to spare. You could also add something to your JS to trigger an "It's loaded" pseudo-callback to make sure it has time to load if you're using it to make something else happen.

In most cases, it's just a matter of loading into a variable reference. Which shouldn't make any difference. Shouldn't need a callback in that case.

Tanmay's issue was likely the script bombing out somewhere. Unsure since I don't see an example that wasn't working:)

Steve

Michael Laudone

I never saw a solution to the middle inital issue: Here's what I did:

<script type="text/javascript" language="JavaScript">
function getName(){
 var sName = lmsAPI.LMSGetValue("cmi.core.student_name");
 sName = sName.replace(',','');
 var aSplit = sName.split(" "); 
 player.SetVar("v_LastName", aSplit[0]);
 player.SetVar("v_FirstName", aSplit[1]);
 player.SetVar("v_MiddleInitial", aSplit[2]);
 }
</script>

Miranda Verswijvelen

 We are successfully using it in a privacy course, where we pull the learner's name through to feature in privacy breach scenarios. It has a great sensitising effect on them!

 

Bid problem though: This works brilliantly for us in Firefox and Chrome, but fails completely in IE.

Any thoughts?

Cindy Pandke`

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.

Helena Smith

We have an outside source that sends emails to the users such as: New User templates, change password/reset

 

The variable set up for user name is %%susername%%

What type of coding is this?  

If I want to set up a text box with the user typing in their names, will i need to use this type of coding??

Ashley Terwilliger

Hi Helena,

In Storyline you use the % % signs around the name of a variable to reference whatever is being held within that variable (be it text, numeric value, a t/f). This is described here. 

If you're looking to pull in code from your LMS, you'll need to look at using some Javascript, which I'll have to defer to the community for. 

Ashley Terwilliger

Hi Helena,

I would say not - the Javascript that would be used in Storyline is as shown here. You'd likely need to be using Javascript to pull information from the LMS into your Storyline course such as name - and if you need to report to your LMS on variables within  Storyline you'll want to use the method here. 

Philip Lima

Really hoping someone can help. 

I am assuming the answer is something really silly.  We have been retrieving the learner name from our LMS on many courses.  all of a sudden, it will not work.  Here is the slide that retrieves the name.  Does anyone have any idea why this won't work?

Steve Flowers

Hi Philip -

If the LMS changed something, it could require a slight shift. Add the bolded line below to see if something changes.

var player = GetPlayer();

lmsAPI=parent;
var myName  = lmsAPI.GetStudentName();

var array  = myName.split(',');
var newName = array[1] + '  ' + array[0];

player.SetVar("newName", newName);

Steve Flowers

What LMS is this running in? Does anything alert adding this line to the top?

lmsAPI=parent;
var myName = lmsAPI.GetStudentName();
alert(myName);

Another potential cause is a script erroring out and preventing the call from executing. In Chrome (or another modern browser), try opening the browser console. Hamburger menu > More Tools > Developer Tools. Click the console tab then drop down the menu at the top labeled <top frame>, selecting the storyline window and look for errors to appear in the console.