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
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);
- PhilipLima1Community Member
Hi Steve. Thanks for the suggestion, but that didn't fix it.
- PhilipLima1Community Member
Hi Steve. Thanks for the suggestion, but that didn’t fix it.
- SteveFlowersCommunity Member
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.
- PhilipLima1Community Member
when running adding:
alert(myName);
a pop-up does appear with my name.
- PhilipLima1Community Member
but, my name still does not appear on the screen in the course itself.
- SteveFlowersCommunity Member
Ah! Found a problem. You need to create the variable in the variable manager. Otherwise the SetVar call won't work and the %newName% macro will just pull from nothing. I'm guessing it'll just continue to display %newName%, correct?
- PhilipLima1Community Member
OMG! cannot believe we forgot to add it to the variable manager! Testing now.
- PhilipLima1Community Member
That did it Steve. I can't believe it. I am 13 hours in on a marathon day. Example of the law of diminishing returns - possibly.
I really appreciate the help.
- PhilipLima1Community Member
Thank you Steve!
- MarkCairnsCommunity Member
Hi Stephanie,
I've added the missing variable and tested it in Scorm Cloud. It works now. See attached.