Pulling first name from LMS
Apr 19, 2017
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
44 Replies
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
James, thanks for adding to the debate. I have the same issue as you (noted above). I have confirmed that it is not a moodle issue as I have tested on more than one LMS.
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);
-------------------------------------------
Thanks Matthew & Chris.
I tried the code posted by Chris/linked to by yourself and works a treat! Thank you.
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
I've managed to post a solution that Frankenstein's all of these and tests for html5 over on this thread .
I've taken some stuff from Matthew's solution and some stuff from others. this has been tested in HTML5, Flash and in Moodle.
Thanks for sharing John - looks like some good conversation happened in that thread as well :)
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
Hi all, is there a way to omit the middle name? Our LMS (SuccessFactors) has separate fields for First, Middle and Last name, but the script is pulling the first+middle.
Hi Mattews,
You seem to be the one who could fix my problem.
On a french LMS, names have accentuated letters ( ie : é). What is retrieved is a "é" instead of an "é".
What would be the piece of code to transform that ?
Thank you for your help.
Have a nice day
Philippe
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
Well you are welcome, good to know that some of this older code is useful.
Hi Matthew,
Could you help me with a java script, if I needed to pull in the learners initials from their first and last name from the LMS? (Example, I need Andrew Ford to appear as AF)
Thanks!
This may work, untested... let me know:
// Capture first initial from a variable
full_name = full_name.str.charAt(0);
first_name = first_name.str.charAt(0);
or maybe this one:
// Capture first initial from first and last name
var last_name = array[2];
first_name = first_name.substring(0, 1);
last_name = last_name.substring(0, 1);
Does this work for all LMS systems or specific ones? I am trying this with CSOD and it does not work.
This works with LMS' which adhere to AICC/SCORM standards, and are populating the field where the user's name is expected (retrieved using cmi.core.student_name) with the user's full name. The prescribed format is Last Name, First Name, Middle Initial, with the last name and the first name separated by a comma. Spaces in the name must be honored.
I am struggling with using JavaScript to capture the user's first and last names from the LMS (Vector Solutions). They store the user name as "Firstname, Lastname, Middle". This is the code I am using but it is not working. I was able to insert the date using JavaScript.
var lmsAPI = parent;
var name = lmsAPI.GetStudentName();
var nameArray = name.split(",");
var lastName = nameArray[1];
var firstName = nameArray[0];
var player = GetPlayer();
player.SetVar('first_name',firstName);
player.SetVar('last_name',lastName);
Hi Glenda,
From what I see in your code, you must declare the "player" variable before making the API call.
Try this:
var player = GetPlayer();
var StudentNameIn = lmsAPI.GetStudentName();
var array = StudentNameIn.split(',');
var StudentName = array[1] + ' ' + array[0];
player.SetVar("StudentName", StudentName);
If you wish to split the name in two variables, you may use your approach instead of "StudentName".
Thanks, Lucio. THAT worked!