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 windowif (win.hasOwnProperty("GetStudentID")) return win;
// all done if no parentelse if (win.parent == win) return null;
// climb up to parent window & look thereelse 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 variablefull_name = full_name.trim();first_name = first_name.trim();
// Remove blank space from the end of variablefull_name = full_name.replace(/\s+$/, '');first_name = first_name.replace(/\s+$/, '');
// If value exists change variable, if not change name to participantif (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
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-09e35 years agoCommunity Member
Well you are welcome, good to know that some of this older code is useful.
Related Content
- 2 months ago
- 8 months ago
- 3 years ago