Forum Discussion

JaclynBlum-55cb's avatar
JaclynBlum-55cb
Community Member
29 days ago

Pull Just First Names from LMS with JavaScript without Middle Names

Hello all! 

I've been looking through all the threads that I could find about using JavaScript to pull learners names from the LMS to use in courses, and have copied one that works well in SCORMcloud. 

However, when I use it with SuccessFactors it pulls the first name AND middle name for some reason. 

Any ideas for how to fix this?? Thanks so much!

Here's the code I was using: 

 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);
var myName = lmsAPI.GetStudentName();
var array = myName.split(',');

var full_name = array[1] + ' ' + array[0];
var first_name = array[1];

// Remove blank space from the front of variable
full_name = full_name.trim();
first_name = first_name.trim();

// Remove blank space from the end of variable
full_name = full_name.replace(/\s+$/, '');
first_name = first_name.replace(/\s+$/, '');

// If value exists change variable, if not change name to participant
if (first_name) {
player.SetVar("username", first_name);
}else{
player.SetVar("username", "Participant");
}
No RepliesBe the first to reply