Forum Discussion

SvenSpillebe516's avatar
SvenSpillebe516
Community Member
3 months ago

Get learnername, coursename and coursedate from Cornerstone LMS

I have been tinkering to get the learername, coursename and coursedate from cornerstone lMS ( Cornerstone on demand) but am unable to make it work.

i have made it work in Scormcloud but am unable to find the correct way.

can someone be of help.

 

thnx

 

3 Replies

  • StefanS's avatar
    StefanS
    Community Member

    The javascript code below gets the learner name from Cornerstone on demand, using SCORM 2004 format.
    1) create 3 text variables in storyline: first_name, last_name, full_name
    2) create text fields that show the content of the variables
    3) create a button to execute the code
    4) publish the course in SCORM 2004 format
    5) run the course in Cornerstone and execute the code
    6) you will see the name(s) 

    (Note: I am struggling with getting the learner name with a course in xAPI format in Cornerstone on demand. Maybe someone can help.)

    Here is the working code:

    function findLMSAPI(win) {
        if (win.hasOwnProperty("GetStudentName")) return win;
        else if (win.parent == win) return null;
        else return findLMSAPI(win.parent);
    }

    var lmsAPI = findLMSAPI(this);
    if (lmsAPI) {
        var player = GetPlayer();
        var name = lmsAPI.GetStudentName(); // z. B. "Max Mustermann" oder "Mustermann, Max"
        console.log("Name vom LMS:", name);

        var firstName = "";
        var lastName = "";

        if (name.includes(",")) {
            // Format: "Nachname, Vorname"
            var parts = name.split(", ");
            lastName = parts[0];
            firstName = parts[1];
        } else {
            // Format: "Vorname Nachname"
            var parts = name.split(" ");
            firstName = parts[0];
            lastName = parts.slice(1).join(" "); // Falls mehrere Nachnamen
        }

        player.SetVar("first_name", firstName);
        player.SetVar("last_name", lastName);
        player.SetVar("full_name", firstName + " " + lastName);
    } else {
        console.error("LMS API nicht gefunden.");
    }