Forum Discussion
Pulling first name from 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
- MaureenMatsumot4 years agoCommunity Member
Thanks to everyone who started this post and provided input.
Thank you, Kevin,
Your version worked for my LMS, Sum Total.
When I copied the javascript from this post above, it didn't work. But when I copied it from your Storyline file, it worked.
Thanks again,
Maureen
- KevinBrake-09e34 years agoCommunity Member
Well you are welcome, good to know that some of this older code is useful.