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
- MirandaVerswijvCommunity Member
I love this community - we were just discussing this morning whether this would be possible - and here it is, demo and all.
Thank you so much :)
Glad that this thread helped you out Miranda!
- TanmayGhoshCommunity Member
Hi,
I'm trying to display student name and date in the certificate, that appears on the Result slide. I have used the "Execute Javascript" trigger with code written like:
var player = GetPlayer();
var myName = lmsAPI.GetStudentName();
var date1 = new Date();
player.SetVar("displayDate", date1);
player.SetVar("studName", myName);
Now the problem is it is not working in iOS device, as HTML5 output is running there.
Is there any way to execute javascript in HTML5 output also?
If not, then how can I fetch Student name and Current date in Articulate Storyline 2, so that they can be displayed in the Certificate.
Tanmay
- SteveFlowersCommunity Member
Looks like you resolved this below. There isn't a good reason why the code you've shown here wouldn't work in HTML5. I am not sure if iOS will like the Date() object pushed into a variable.
I've used the same code for both Flash based and HTML5 output for quite awhile and it's worked consistently in all cases.
When testing, use a modern browser's console to show where the script is being stopped.
- AlexYong1Community Member
Hi Steve,
So this is a very long thread and the original code provided way back when this thread was first started wasn't supported in HTML5 so that's why I was looking back for any new updates or changes that would allow it to work.
Hi Tanmay,
Javascript is not something we offer support for, but I did want to point you to the information in regards to our Javascript best practices and examples.
- AlexYong1Community Member
Has anyone figured out how to achieve the ability to pull a student name from the LMS which is supported in HTML5? I've been watching this thread for quite some time hoping for a solution. Is it just not possible?
Thanks Tanmay for coming back to share the file here!
- AlexYong1Community Member
Thanks for sharing Tanmay!
- SteveFlowersCommunity Member
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
- EricDumasCommunity Member
Great info, thanks for all these insights.
I really need to learn more about JavaScript, it seems to enhance so many applications I use !
Javascript opens up a lot of possibilities - so I'm glad you found this thread helpful. :-)