Getting student name from the LMS and using it in Articulate

Jun 08, 2017

In the LMS we are about to use, we can get the student name since the SCORM runtime variable for it is "cmi.core.student_name".  However, how do I get it as a variable in Articulate at run time? 

40 Replies
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);

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

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.

David Sweeney

Matthew,

I am hoping you might be able to help me on this as I have a very similar issue to Candice above.  I had this working for me for a year or so - retrieving both first and last names.  However we upgraded our LMS and I am not sure if it is linked but I started to see "undefined" inserted before the full name.  Going on your suggestion above, that the LMS might be storing the name in an unusual way, I updated the line in the code from:

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

to

var newName = array[0];

and this worked, i.e. it retrieved the full name and the "undefined" was not included.

My question is, have you seen this more frequently now or do I need to investigate why the LMS is storing the name in this way?  We use Moodle.

 

Regards,

David 

 

Sue Ashby

Thank you so much for this.  Even though this was published so long ago, it helped me this morning when my js snippet stopped working.  For some reason var myName = lmsAPI.GetStudentName(); was working in my Storyline file for quite some time and then stopped. I suspect that Moodle was updated or something. Anyway.  I changed lmsAPI to SCORM_ and now it works and retrieves the student's first name. I am eternally grateful!

Julian Rose

It might seem fairly obvious (retrospectively), but to note the methods here will not work when publishing a storyline to LMS / LRS with Report to an LMS = xAPI. Presumably the same is true with CMI5.
When you publish to xAPI the result is "undefined", similar to results others have reported using older LMS systems. 
They do work fine when Report to an LMS = SCORM 1.2 or 2004 accordingly. 

When publishing to xAPI we still get scormdriver.js in the output ../lib/.
There are snippets of code that look like they are to do with xAPI or CMI5. Is this still work in progress?
So now I must look for xAPI "equivalent" methods... maybe more javascript...post and get...

Robert Webbe

I have the same issue as Julian Rose, I like to retrieve the users first and last name but must publish my courses to xAPI. As Julian mentioned, that's not working. Is there someone who understands javascript and get it to work via scormdriver.js? When I review this file via Notepad, I see var strFirstName; and var strLastName; but don't know how get that working.

Jürgen Schoenemeyer

for xAPI it is not possible with scormdriver.js (there is no connection from course to LMS)

have a look in this video

https://www.youtube.com/watch?v=OGYTxy-ru4E&t=422s

the user name (if there is one) is encoded in the start url of the course

the details dependes on the LMS you use - probably for security reasons there is no name transmitted at all, but only a anonymous ID