Getting username from Cornerstone

Dec 01, 2022

Hi all!

Trying to grab the username and put it into three different variables.

Name (Full name)

First Name

Last name

I have below code, which only gives me the name and the last name. The last name is the user full name. What am I missing? I suspect it's the way Cornerstone is writing the name. I'd like to just use the first name as things otherwise get too formal. But I need the full name as well.

var player = GetPlayer();

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 newName = "Guest";

if (lmsAPI)
{
var name = lmsAPI.GetStudentName();
var nameArray = name.split(", ");
var firstName = nameArray[1];
var lastName = nameArray[0];
var player = GetPlayer();
player.SetVar('first_name',firstName);
player.SetVar('last_name',lastName);
}
    
player.SetVar("name", name);

9 Replies
ANNE Learning

Found the solution myself. It was quite rightly because Cornerstone didn't use comma to split the name. This is the solution:

// Assuming you have a text variable called "name" in SL

var player = GetPlayer();

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 newName = "Guest";

if (lmsAPI)
{
var name = lmsAPI.GetStudentName();
var nameArray = name.split(" ");
var firstName = nameArray[0];
var lastName = nameArray[1];
var player = GetPlayer();
player.SetVar('first_name',firstName);
player.SetVar('last_name',lastName);
}
    
player.SetVar("name", name);

Joseph Francis

Yeah, every vendor's LMS has to be different with the delimiters and object positions. 🙄

Absorb LMS returns the GetStudentName query the same way Cornerstone/Saba does, with the learner's first name in position 0 in the array and the last name in position 1 in the array, even though SCORM's cmi.core.student_name (which derives from AICC's cmi.core.student_name) specifies the format as:

Last name, first name and middle initial. Last name and first name are separated by a comma [emphasis mine]. Spaces in the name must be honored.
Joseph Francis

Sorry, no. In AICC (where SCORM drew its data elements from) and in SCORM, the student core data elements consist of Student ID and Student Name.

While AICC also has optional student demographic data elements including company, street address, city, state, country, and telephone; title, experience, familiar name, and years experience; instructor name and class; and native language, SCORM did not carry over those elements into its data model.