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

211 Replies
Steve Flowers

Hi Angela - 

Depends on how / where it's displayed. When the course launches, if the info is contained in the query string ?value=name, then it's pretty easy to grab. 

If the info you want to grab appears in a parent window or frame consistently, it can be scraped with some creative javascript. Try this. You can retrieve your name from the title attribute of the user image in the upper right of the elearning heroes site by adding this to the developer's console:

console.log(document.getElementsByClassName("user__img")[0].getAttribute("title"));

Right-click the window and choose inspect (in Chrome) then click the console tab. Paste that line in there. The same concept applies to anything that appears in a page. You can scrape that data from a displayed page easily. Same concept applies to pages that aren't displayed. You can grab stuff from a page return and chisel little bits of data if the page address is reliable and the "address" of the information within the DOM is predictable. 

Anything that appears in a page structure can be grabbed from Storyline as long as the user has access to the page.

Kyle Mullaney
Steve Flowers

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);

This is not working in HTML5 on Sakai. It does work in flash on Sakai.

Lucio P

If ever the "Works in all" portion doesn't work as is, try preceding it with the following script:

var player = GetPlayer();

function findLMSAPI(win) {
// look in this window
if (win.hasOwnProperty("GetStudentID")) return win;

// all done if no parent
else if (win.parent == win) return null;

// climb up to parent window & look there
else return findLMSAPI(win.parent);
}

var lmsAPI = findLMSAPI(this);

… and the rest following "...GetPlayer() …"

phil Mek

Hello everybody,

I read every single message in this thread, and in some others.

But couldn't find what I am looking for :

My client LMS (Talentsoft) in SCORM 2004, can display cmi.learner_name as a variable.

I tried many many many syntaxes to grab this data, but I guess the only working one wasn't in my scope !

Can anymone help me ? what is the syntaxt to grab this value ?

thank you for the help

Philippe

 

phil Mek

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