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?
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.
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);
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!
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:)
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.
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.
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.
I haven't seen the double % signs, and that's not a built in feature of Storyline. Are you seeing that in a .story file that you set up or that someone else shared with you? Anymore information you could share would be helpful in terms of identifying that.
In Storyline I have seen the %name% for example but we are using a third party server with our emails and LMS and for usernames they use %%ABC_username%%
I was trying to figure out the difference between one percent sign and two.
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.
Hey guys! this is almsot exactly what I was looking for...Just that i want to use the first name, not the full name. I tried using just the Array[1] and removing everything else from the JS script but it doesnt work. Suggestions?
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?
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.
213 Replies
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.
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:
Works in all:
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!
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
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>
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. :-)
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?
Hi Miranda -
What version of IE?
Hi Steve,
We have encountered it on IE 10 and 11. We are using Totara LMS (the commercial version of Moodle)
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.
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??
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.
Ok thank you. Let me take a look.
So the %% signs around the variable make the information unique, as oppose to a single % surrounding the variable?
I haven't seen the double % signs, and that's not a built in feature of Storyline. Are you seeing that in a .story file that you set up or that someone else shared with you? Anymore information you could share would be helpful in terms of identifying that.
In Storyline I have seen the %name% for example but we are using a third party server with our emails and LMS and for usernames they use %%ABC_username%%
I was trying to figure out the difference between one percent sign and two.
Is this Javascript?
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.
Hey guys! this is almsot exactly what I was looking for...Just that i want to use the first name, not the full name. I tried using just the Array[1] and removing everything else from the JS script but it doesnt work. Suggestions?
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?
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);
Hi Steve. Thanks for the suggestion, but that didn't fix it.
Hi Steve. Thanks for the suggestion, but that didn’t fix it.
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.
when running adding:
alert(myName);
a pop-up does appear with my name.