Passing username from Moodle to Storyline via Javascript

Nov 16, 2017

I have a certificate at the end of one of my SL360 courses that takes the user's name from the LMS and displays it on the certificate. To do this I execute the following javascript:

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

This is tested and works well in SCORM Cloud but it doesn't work in Moodle. I'd be grateful if anyone has any clues that might help.


8 Replies
David Tait

Thanks for the suggestion Owen,

The issue seems to have been introduced when I've published my old SL2 courses in SL360, possibly something to do with switching to HTML5 with Flash fallback during publish perhaps.

The info in the following thread has provided a solution that seems to work in Chrome, Firefox and IE: 

Tristan Hunt

I found the same when switching to 360. Here is the code we are currently using.

I found the username came through around the wrong way so had to split it out. 

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 last = array[0];
var first = array[1];
first = first.substring(1);
var firstChar = first.charAt(0);
var lastChar = last.charAt(0);
var fandl = firstChar.concat(lastChar);
var fullname = first.concat(" ",last);
player.SetVar("Name", fullname);

This discussion is closed. You can start a new discussion or contact Articulate Support.