Forum Discussion
EvitaPurzale-e0
3 years agoCommunity Member
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 ...
EvitaPurzale-e0
3 years agoCommunity 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);
Related Content
- 8 months ago
- 9 months ago
- 9 months ago