Hi all - I'm wondering if anyone might be able to put together a step-by-step guide as to how to set up a variable / javascript function for this? (i.e. pulling a user's first name from the LMS).
...
I have revised the code a little with a few improvements. ...and, I can confirm this code works with Saba LMS and Moodle. The attached file is for Storyline 360, but the code itself should work with Storyline 2 files. Published setting format: HTML5 with Flash fallback and also works with HTML5 only setting!
Be sure to create a variable named username in Storyline.
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 full_name = array[1] + ' ' + array[0]; var first_name = array[1];
// Remove blank space from the front of variable full_name = full_name.trim(); first_name = first_name.trim();
// Remove blank space from the end of variable full_name = full_name.replace(/\s+$/, ''); first_name = first_name.replace(/\s+$/, '');
// If value exists change variable, if not change name to participant if (first_name) { player.SetVar("username", first_name); }else{ player.SetVar("username", "Participant"); }
//Modified and tested by Kevin Brake
The code above would be: Execute JavaScript, When timeline starts