Forum Discussion
Getting username from Cornerstone
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);
- EvitaPurzale-e0Community Member
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); - PhilMayorSuper Hero
Love that you answered your own question
- JoeFrancisCommunity Member
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.
- PhilMayorSuper Hero
Not sure if it was Absorb. One LMS kept giving me the middle name
And 50% of the time it came through as undefined had to write a simple statement to ensure it didn’t display in the course.Sent from my iPhone
- JoeFrancisCommunity Member
Middle name? Well THAT'S useful 🙄
- DanielKlinger-fCommunity Member
Can I ask a wild question? Is it possible to get a little deeper? For example - lets say we store in the profile a person's Job Title - can the same method be used to retrieve a Job Title?
- JoeFrancisCommunity Member
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.
- DanielKlinger-fCommunity Member
And then secondly? What if we are after the true username - not necessarily the first and last name????
- EvitaPurzale-e0Community Member
I think at least job title might be possible. I have no idea how to obtain that though. Cornerstone support is probably your best bet.
As for the true username, I don't think that's possible for security reasons.