49 Replies
Kevin Hayes

I've been trying to use this code on SCORM Cloud but it isn't working for me:

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 newName = array[1] + ' ' + array[0]; 
player.SetVar("newName", newName);

Is it because SCORM cloud stores the name under a variable name other than StudentID? 

Has anyone managed to get this to retrieve the learner ID from SCORM cloud?

 

Nathan Leavitt

The lmsAPI.GetStudentName(); method no longer works for me when I publish to HTML5 only. Here's the code that I use for HTML5:

//This trigger is set to execute when the timeline starts. In order for it to work, this slide requires a variable "newName".
//Get User Name embedded into file from LMS
var myName = SCORM_GetStudentName();

//SCORM has last name, first and we are switching it around to first last.
var array = myName.split(',');
var newName = array[1] + ' ' + array[0];

//Set the variable
var player = GetPlayer();
player.SetVar("newName", newName);

FYI, we’ve found that although the lms.js file is still included in the published HTML5 zip package, it’s not actually used and all its functions and variables aren’t used in our LMS. I’m not sure if that has something to do with our LMS (Saba Cloud) or something else. Regardless, that’s why the lmsAPI variable is undefined in our LMS. Instead I used the SCORM_GetStudentName(); function from SCORMFunctions.js.

Gina Labato

Hi all, revisiting this post. 

My team and I are trying to do the following using JavaScript:

1. Retrieve a username from the LMS

2. Culminate user's score on a quiz into a LeaderBoard. 

For now, we're trying to tackle the first problem and have realized that all of the codes provided in these threads do not work with Docebo LMS for some reason. Any suggestions? 

None of us are versed enough in Javascript to know how to manipulate the code for our LMS more than just plug it in and test. 

Nisha Makan

Hi. I have a Storyline SCORM package embedded in an iframe on my LMS course page. I'm wanting to include the learners name in the Storyline file however the name is not showing up as the embedded course doesn't seem to talk to the LMS. I am getting a course saying it is unable to talk to the LMS API.

I tested the course by running it like a normal eLearning course which launches from the training course page in a new window - in this instance the names are appearing in the module, so I know the Execute Javascript code is working correctly.

Does anyone have any advice on how I could get this to work in my iframe version? The LMS I am using is Totara.

Kevin Hayes

This code is working for me on Totara - sadly I can't advise on it as I either found it within this thread or a previous discussion:

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 newName = array[1] + ' ' + array[0];
player.SetVar("newName", newName);

var lmsAPI = findLMSAPI(this);
var StudentID = lmsAPI.Getstudent_id();
player.SetVar("StudentID", StudentID);

Matthew Bibby

Nisha, the code that Kevin provided should work for you.

Although this example may better explain what's happening, which can be helpful if you need to modify the code to suit your project.

// Let's make sure we can talk to the LMS:
function findLMSAPI(win) {
if (win.hasOwnProperty("GetStudentID")) return win;
else if (win.parent == win) return null;
else return findLMSAPI(win.parent);
}

// Let's make sure we can talk to Storyline:
var player = GetPlayer();

// Let's grab the student's name from the LMS (SCORM 1.2):
var name = lmsAPI.GetStudentName();

// If publishing to SCORM 2004, use the below instead:
// var name = lms.API.SCORM2004_GetStudentName();

// The name will be LastName, FirstName - so let's rearrange that:
var nameArray = name.split(", ");
var firstName = nameArray[1];
var lastName = nameArray[0];
var fullName = firstName + ' ' + lastName;

// We now have the first name, last name and full name stored seperately. If we want to use these in Storyline, we will need some appropriately named text variables. They should be first_name last_name and full_name. You probably don't need all three. So decide what is most useful (usually it's first name or full name) and just add the variable for that. Or you can have all three if you really want. I don't mind. Once you have the appropriate variables set up in Storyline, you can include the relevant lines of code below:
player.SetVar('first_name', firstName);
player.SetVar('last_name', lastName);
player.SetVar('full_name', fullName);

// Then, if we want to grab the student ID from the LMS, we can use the below code. If you are lucky, this will be an email addresses, but don't be suprised if it's just a boring old username. You'll need a variable in SL called student_id for this to work. Delete this code if not using it:
var studentID = lmsAPI.Getstudent_id();
player.SetVar("student_id", studentID);

Hopefully, that helps explain things a bit better. Any questions, let me know. 

Ryan Kruger

Any chance I can call on anyone to help me identify how I get similar functionality in Litmos LMS publishing as SCORM 1.2 - beyond the learner name, I'd like to collect another profile attribute as well... I'm using:


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 myName = lmsAPI.GetStudentName();

var array = myName.split(',');

var LMSName = array[1] + ' ' + array[0];

player.SetVar("name", LMSName);

 

This successfully writes the learner's first and last name to the eLearning displayed from Litmos.

What I'd like to get now is a custom field from the learner's profile in Litmos. According to our admin, this particular field is called "CustomField2".

Joseph Francis

Quite a while ago, Sam Coulson replied to a request surrounding retrieving data from an LMS. He included the list of variables LMSAPI.js includes. These are industry-standard variables and functions, originally used by  AICC-compliant LMS' and courses.

IF your LMS exposes one or more of these variables to eLearning courses, you MAY get a response when you query the LMS through them and/or attempt to write data using them. As Sam says in his message, "this is advanced coder territory, reverse-engineer with caution."

https://community.articulate.com/discussions/articulate-storyline/help-with-javascript-and-pulling-data-from-an-lms

Speaking from experience, I was able to Get and Set several status' from (oddly enough) an older LMS, which I was unable to then replicate on a newer LMS, including LanguagePreference, Audio, and SpeedPreference. Other functions and variables, including student demographic data, are non-existent, probably because they aren't key data points and each LMS treats them a little differently.

Candice Boult

I know this is an old thread but I'm hoping someone can help me here. I'm very much a beginner.

I have used the code below (from earlier in this thread) and it works great. The student ID bit isn't working for me, it just shows on the LMS as 'undefined', which is fine because I don't want the ID, I only want the name but have no idea how to amend the code to remove the ID bit.

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 newName = array[1] + ' ' + array[0];
player.SetVar("newName", newName);

 

Any help would be really appreciated. Thanks :)

Candice Boult

Thanks for the fast reply Matthew. You can tell I'm very new to javascript.

The problem I am getting is that at the start of the name it says 'undefined'. I tried a code from another thread on here to only show the first name and that worked fine (pasted below), but for things like certificates etc it would be nice to have the full name pull through.

 

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();

// remove last name from array

var array = myName.split(' ');

var newName = array[0];

player.SetVar("newName", newName);ar("newName", newName);

 

I'm using the most up to date version of storyline 360, and exporting the to scorm 1.2.

Thank you

Matthew Bibby

It sounds like LMS might be storing names in a non-standard way. For example, rather than using the first name field to store 'Candice' and the last name field to store 'Boult', they are likely storing 'Candice Boult' in one of the name fields and leaving the other one blank. So the code will need to be modified to work with that if that's the case. Can you please show me exactly what the output looks like? 

Candice Boult

I have attached the storyline file I was working with. Please don't laugh at the slide I made, I just wanted to show others in my team what I had learnt so it was the most basic thing ever.

I have added a couple of slides that have screenshots of what I can see when it is used on the LMS and also the details stored on the back end of the LMS.

Let me know if you need any more info. I really appreciate you looking at this.