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
Thanks Matthew and Lucio - this is working great :)
Except in one instance, when calling to display the last name, a random comma appears after it.
This is what I have used:
var lmsAPI = parent; var name = lmsAPI.GetStudentName(); var id = lmsAPI.GetStudentID(); var nameArray = str.split(" "); var firstName = nameArray[1]; var firstInitial = firstName.charAt(0); var lastName = nameArray[0]; var cleanLastName = lastName.replace(/[^a-zA-Z]/g, ""); var userName = firstInitial + cleanLastName; var userName = userName.toLowerCase(); var player = GetPlayer(); player.SetVar('first_name', firstName); player.SetVar('last_name', lastName); player.SetVar('first_initial', firstInitial); player.SetVar('email', id); player.SetVar('username', userName);
This is how the reference appears on the slide:
Username: CORP\%first_name%.%last_name%
This is how it appears when published:
Username: CORP\Sal.Milford,
Surname is definitely just Milford in the LMS. Any ideas?
Alzheimer's Australia Vic would like to acknowledge the traditional owners of the land on which we meet and pay our respects to Elders both past & present.
PRIVACY STATEMENT: This email, and any attachments, contains confidential information intended only for the person/s named above and may be subject to legal privilege. If you are not the intended recipient, any use, disclosure, copying or distribution of this transmission is prohibited. If you have received this message in error, please notify the sender immediately by return email and delete the original email and any attachments.
Hey Sally! I wanted to mention that responding via email includes your email signature here. No worries on our end—just wanted to let you know in case you didn’t want to share it publicly. :)
I guess it can't hurt to declare it as "parent" though I haven't been using that line in my cw with SL2, SCORM 1.2. I guess I'll integrate it in my process.