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
- JenniferHadjezCommunity Member
Newbie here - Is there a way for the variable to retrieve the user name without the user having to click a button?
- BrianAllenCommunity Member
Hello Jennifer,
Just add the trigger to execute the javascript to a shape positioned off the slide, and set that trigger to execute at the beginning of the timeline of your slide.
This will execute the trigger automatically and make the value available for you to use.
- JayDharapCommunity Member
Hey Jennifer!
You set up a variable called *newName* (you could call it anything you
want, just make sure the javascript I am about to share with you has the
same variable mentioned)And then you set up a trigger to run at the start of the timeline, to
execute javascript.And in the pace where the javascript is meant to go, you enter this:
var player = GetPlayer();
var myName = lmsAPI.GetStudentName();
var arrayName = myName.split(' ');
var newName = arrayName[0];
player.SetVar("newName", newName);This works for my LMS. I'm no expert, but you can try this and ask around
if this doesn't work. There are versions of this floating around.
- PhilMayorSuper Hero
set the trigger to on timeline start of a slide
Hey Jennifer! Welcome to the E-Learning Heroes community - assistance like you're getting above is the best welcome I could think of!
- JenniferHadjezCommunity Member
Thank you, everyone! What a great response! I got it to work! Yay!
- JamesBonney-EDECommunity Member
Hi All,
In SL1, this code works for me on my Moodle LMS, but in SL2, it doesn't pull the name through. Can anyone tell me why it's no longer working?
var player = GetPlayer();
var myName = lmsAPI.GetStudentName();
var array = myName.split(',');
var newName = array[1];
player.SetVar("newName", newName);
Thanks
James
Hi Lucio!
Hopefully there are some users still subscribed to this thread that will be able to pop in and assist you here. If not, feel free to reach out to a user directly via the 'Contact Me' option on the user profile.
- LucioCommunity Member
Thank you both Leslie and Philip to get back to me.
In the meantime, I found this:
Though I haven't tested any of it yet, it may help someone in the future.
Thanks for sharing Lucio :) There's a wealth of knowledge on the forums for sure.
- JulieJones-2ecbCommunity Member
This post is over four years old and I was wondering if there is an example for Storyline 2 and one that actually works with HTML5? Thanks!
Hi Julie - JavaScript coding is not something that is supported by Articulate, but there is a lot of information here and much more recent than when the thread was started. Hopefully you'll find something to best assist you or someone will be able to chime in and assist.
- HelenaSmithCommunity Member
I think I am confused regarding JS not supported in Storyline...we have JS codes for various things so how is it not supported?
Thank you