JavaScript for obtaining the Learner's name from the LMS

Jan 11, 2024

Hi everyone,

I have looked at a couple of the posts on here and watched a tutorial video by Jeff Batt at Learning Dojo on how to retrieve the learner's name from the LMS and display it automatically on a slide.

I can't seem to get it to work and I am a complete novice when it comes to JS, is there anyone who can help me get it working?

This is the code I have used which is from Jeff Batt:

let player = GetPlayer();
let myName = lmsAPI.GetStudentName();
let array = myName.split(',');
let newName = array[1] + ' ' + array[0];
                  
player.SetVar("lmsName", newName);

I have tried this with let and with var

Thanks, Adam

1 Reply
Nathanial Hilliard

I use the same  basic code to retrieve the LMS username, so that should be fine. Have you tried looking for error messages in the console (F12 in browser, click console)? Perhaps add some console.log entries to display your variable values as you go.

For example, to display whatever was fetched from the LMS, add this to the line after the variable assignment.

console.log(myName); 

 Also, when setting the reference to lmsAPI:

let lmsAPI = findLMSAPI();

I use this function:

//Function to connect with LMSAPI

function findLMSAPI(win) {

    if (win.hasOwnProperty("GetStudentID")) {

            return win;

    }

    else if (win.parent == win) {

            return null;

    }

    else {

            return findLMSAPI(win.parent);

    }

}