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
- PhilMayorSuper Hero
- RickForgeardCommunity Member
Hi Phil,
Realizing that this post is 4 years old....I was unable to open your SL file as it was made with an older version. I am running Storyline 2 Update 11. Can you save and post with a later version?
Thanks Rick
- WendyFarmerSuper Hero
Hi Rick
when you try to open the file it should give you the option to upgrade to SL2 - do you not see that pop up box?
- OgbishBarrowCommunity Member
Hello , and thanks for this, Phil, but it seems like the file may have been corrupted, as all I see is pages of code. Can you please send an updated version via email to gbitse@gmail.com. Many thanks for your help
- OgbishBarrowCommunity Member
Hi, okay I have downloaded this, please where do I insert it
- SteveFlowersCommunity Member
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);- AlexYong1Community Member
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!
- KyleMullaneyCommunity Member
This is not working in HTML5 on Sakai. It does work in flash on Sakai.
- BrianAllenCommunity Member
I'd be curious to know if Sakai exposes student name as part of it's API... Not sure if this is an industry standard, and not sure if Sakai adheres to those industry standards.
- SteveFlowersCommunity Member
Give this a shot:
var player = GetPlayer();
lmsAPI=parent;
var myName = lmsAPI.GetStudentName();
var array = myName.split(',');
var newName = array[1];
player.SetVar("newName", newName);
- JamesBonney-EDECommunity Member
Steve, I salute you. Once again helping me out on here.
Really appreciate, thank you!
- RickForgeardCommunity Member
- BrianAllenCommunity Member
Rick, we also use SumTotal. I've got a couple of working examples of this script in Storyline 2 that we've tested in SumTotal. Let me know if you have trouble getting things working.
- SteveFlowersCommunity Member
Haha, that's what I get for multi-tasking. Phil's example demonstrates it the rearrangement. lmsAPI.GetStudentName() and SCORM_GetStudentName() should return identical values.
var player = GetPlayer();
var myName = lmsAPI.GetStudentName();
var array = myName.split(',');
var newName = array[1] + ' ' + array[0];
player.SetVar("newName", newName);
- philMekCommunity Member
Hello again,
Matthew Bibby gave me the answer. It works perfectly in Talensoft LMS.
Be aware that I only needed the firstname.
Here is his code to close my question.
function findLMSAPI(win) {
if (win.hasOwnProperty("GetStudentID")) return win;
else if (win.parent == win) return null;
else return findLMSAPI(win.parent);
}
var lmsAPI = findLMSAPI(this);
var name = lmsAPI.SCORM2004_GetStudentName();
var nameArray = name.split(',');
var firstName = nameArray[1];
// var lastName = nameArray[0];
// var fullName = firstName + ' ' + lastName;
var player = GetPlayer();
player.SetVar("Name",firstName);
Philippe
- MichaelLaudoneCommunity Member
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> - 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?
- SteveFlowersCommunity Member
Have been using the methods listed in the thread for years to get this to work with HTML5.
//this might not be required depending on how your LMS nests the API. Try with then comment out if it does not work in a test publish.
lmsAPI=parent;
//This splits the username sent by the LMS by the comma and creates a string Firstname Lastname.
var userName=lmsAPI.GetStudentName().split(',')[1]+" "+lmsAPI.GetStudentName().split(',')[0];
//get storyline's player
var player=GetPlayer();
//set a player variable in your storyline file to the string created above. Make sure the variable exists in Storyline.
player.SetVar("storylineNameVariable",userName);
Works every time for me in HTML5.
- SteveFlowersCommunity Member
Matthew's find-the-api-automatically method should work as well:
As with all, test it first. I tend to stick with my test and revise method. The approach illustrated at Matthew's link did fail for me once but I didn't take the time to figure out why.
- SteveFlowersCommunity Member
Hi Bruce -
Sort of... AO doesn't use SCORM, so the same method can't be used. What I was successful with was picking up the email address / username from the launching window. This only works when the user logs into AO first. If logging in using a guest link, it will fail. This also only picks up the account email and won't be able to access the first / last name since there isn't a way to get to that as far as I've found using any kind of API.
Doesn't mean that it doesn't exist:) You might try hitting up the team with a support request. I'd imagine this could be a popular ask.