Pulling first name from LMS

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've read through this discussion (https://community.articulate.com/discussions/articulate-storyline/retrieve-lms-user-name-as-variable) but I'm very green and have had no experience with javascript functions (and only basic variables).

Any help for dummies would be amazing.

Thanks,

Sal

49 Replies
Sally Milford

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?

Thanks,

Sal

Leslie Foster

If I publish courses in flash or flash +html5 fallback...then everything works. If I publish in html5 only or html5 + flash fallback....nothing works, no data is pulled from Moodle. Given it works in flash with the same browser configuration, then I assume javascript is working in the browser. I have tested in Chrome, Edge and Firefox and always get the same result in all browsers.

James Bonney

Hi All,

The original code posted by Matthew works in Flash/HTML5 fallback, but not with HTML5/Flash fallback:

var lmsAPI = parent;
var name = lmsAPI.GetStudentName();
var nameArray = name.split(", ");
var firstName = nameArray[1];
var player = GetPlayer();
player.SetVar('first_name',firstName);

Any idea on how to get this working with HTML5/flash fallback?

Thanks

james

Chris Pim

I think this works in Moodle - solved by someone else a couple of weeks ago.

---------------------------

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 newName = array[1] + ' ' + array[0];
player.SetVar("newName", newName);

-------------------------------------------

Matthew Bibby

Hi James,

That code works fine when published as HTML5/Flash in SCORM Cloud.

Here is an invitation to a demo in SCORM Cloud so you can test for yourself. For this demo, I've used the code you've included above and published as HTML5/Flash. 

I suspect you are running into issues due to the LMS you are using. You might find that the code shared in this thread will work in your LMS. 

It would be great if Articulate could fix this up so the HTML5 and Flash output are consistent regarding the lmsAPI as this seems to be causing issues for a few people. 

Edit: I've reached out to support regarding this issue (#01074435).

ilana Dubovi

Hi all,

I've read through this discussion. 

Can you please help me to set up an execute  javascript  for transmitting score from HTML5 to moodle.

I've been using for Flash the following code, but seems that is not working with HTML5 publishing  only:

/*Get player to reference*/


var player = GetPlayer();

/*get LMS API*/

var lmsAPI = parent;

/*set score; the first number is the score*/

lmsAPI.SetScore(player.GetVar("zScores"), 100, 0);

/*set status; possible values: "completed","incomplete", "failed", "passed"*/

 


With thanks,

Ilana

Kevin Brake

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