I know you can have a user fill in a text box with their name and then later use that variable for personalization. What we would like to do is programmatically retrieve the user name from the LMS. Is there a way to set a variable with data from the LMS when the course is loaded instead of having the user enter their name?
var player = GetPlayer(); //might need to use lmsAPI=parent; on some LMS var myName = lmsAPI.GetStudentName(); var array = myName.split(','); var newName = array[1] + ' ' + array[0]; player.SetVar("newName", newName);
This is not working in HTML5 on Sakai. It does work in flash on Sakai.
I'd be curious to know if Sakai exposes student name as part of it's API... Not sure if this is an industry standard, and not sure if Sakai adheres to those industry standards.
Matthew Bibby gave me the answer. It works perfectly in Talensoft LMS.
Be aware that I only needed the firstname.
Here is his code to close my question.
function findLMSAPI(win) { if (win.hasOwnProperty("GetStudentID")) return win; else if (win.parent == win) return null; else return findLMSAPI(win.parent); } var lmsAPI = findLMSAPI(this); var name = lmsAPI.SCORM2004_GetStudentName(); var nameArray = name.split(','); var firstName = nameArray[1]; // var lastName = nameArray[0]; // var fullName = firstName + ' ' + lastName; var player = GetPlayer(); player.SetVar("Name",firstName);
I doubt you pay any attention to this 7 years later - but I just had to say thanks! I have been racking my head against this keyboard for hours...all I needed was the SCORM_ component to work with the LMS we are using. So excited!
I have unfortunately been unable to extract any information using many permutations of the code above from the LMS to my Articulate file. I am testing this with LearnDash.
If anyone has a .story file that works published as SCORM 2004 I would love to see it!
Hey all! I've been using variations of this code for a while now to add my learner's name to in-course instructions and certificates and it's been very useful. Thanks all!
However, I've found that platforms such as Litmos, Docebo, and Cornerstone, tend to add an unwanted space before the first name.
In the past I've worked around this by reducing the left margin on the text box that displays the variable, as I'm not really a coder. But recently I've been 'chatting' with ChatGPT to analyze and refine code.
During a recent chat, ChatGPT provided this updated code. It pulls the user name from the LMS, removes any spaces, and splits it into First Name and Last Name.
And it works!
var player = GetPlayer();
function findLMSAPI(win) { if (win.hasOwnProperty("GetStudentID")) return win; else if (win.parent == win) return null; else return findLMSAPI(win.parent); }
function removeSpaces(name) { return name.replace(/\s/g, ''); }
var lmsAPI = findLMSAPI(this); var myName = lmsAPI.GetStudentName(); if (myName.charAt(0) === ' ') { myName = myName.substring(1); } var array = myName.split(','); var firstName = removeSpaces(array[1]); var lastName = removeSpaces(array[0]); player.SetVar("FirstName", firstName); player.SetVar("LastName", lastName);
That was my concern too - but on my LMS it appears this code parses the name from only the first break. So Brian De Palma is split into Brian and De Palma. As always with Javascript, results may vary but this worked for me on Docebo.
For anyone not using Docebo (which handles complex surnames like De Palma or Van Gogh) , Chat GPT recommended the following amendments to the code:
var player = GetPlayer();
function findLMSAPI(win) { if (win.hasOwnProperty("GetStudentID")) return win; else if (win.parent == win) return null; else return findLMSAPI(win.parent); }
var lmsAPI = findLMSAPI(this); var myName = lmsAPI.GetStudentName(); if (myName.charAt(0) === ' ') { myName = myName.substring(1); } var regex = /([^,]+),(.+)/; var match = myName.match(regex); var lastName = match[1]; var firstName = match[2]; player.SetVar("firstName", firstName); player.SetVar("lastName", lastName);
Is anyone able to share a .story file example where it pulls in a users profile photo from an LMS also? The name comes through perfectly but I don't currently don't have the expertise to re-purpose this and pull in a users photo also. Many thanks everyone, this is the best resource community by far.
I don’t see how you can pull in a users photo there is nowhere in the scorm standard for this. It maybe you can pull a unique I’d from thee LMS you can compare against a company database and pull the picture from there, but you would need to use a web object as Storyline variables are finite and a base64 image would be too large.
Ahh thanks Phil, I asked chat GPT which gave me hope here, this is what it recommended
---------------------
// Get the LMS API object var lmsAPI = parent.GetAPI();
// Check if the LMS API is available if (lmsAPI) { // Get the current user's ID var userID = lmsAPI.GetStudentID();
// Use the user ID to retrieve the profile photo URL var profilePhotoURL = getProfilePhotoURL(userID);
// Update the profile photo in the Storyline content updateProfilePhoto(profilePhotoURL); } else { console.error("LMS API is not available."); }
// Function to retrieve the profile photo URL for the given user ID function getProfilePhotoURL(userID) { // Add your code here to retrieve the profile photo URL from the LMS for the given user ID // Example: // return "https://example.com/profile-photos/" + userID + ".jpg";
return ""; }
// Function to update the profile photo in the Storyline content function updateProfilePhoto(profilePhotoURL) { // Add your code here to update the profile photo in the Storyline content // Example: // document.getElementById("profile-photo").src = profilePhotoURL; }
----------------
If anyone else or even I do get a working version going I'll add to this thread.
A while back, Sam Coulson replied to a request surrounding retrieving data from an LMS. He included the list of variables LMSAPI.js addresses. These are industry-standard variables and functions, originally used by AICC-compliant LMS' and courses.
The SCORM Run-Time Reference Guide describes the data elements supported by the specification. Learner-demographic data (which your LMS may or may NOT support) is confined to:
cmi.learner_id: Identifies the learner on behalf of whom the SCO was launched
cmi.learner_name: Name provided for the learner by the LMS
cmi.learner_preference.audio_level: Specifies an intended change in perceived audio level
cmi.learner_preference.language: The learner’s preferred language for SCOs with multilingual capability
cmi.learner_preference.delivery_speed: The learner’s preferred relative speed of content delivery
cmi.learner_preference.audio_captioning: Specifies whether captioning text corresponding to audio is displayed
While AICC does have several more learner-demographic data elements than SCORM does (including address, company, and years of experience), AICC, which SCORM was based on, did not support a data element for the learner's photo.
213 Replies
This post was removed by the author
This post was removed by the author
This is not working in HTML5 on Sakai. It does work in flash on Sakai.
I'd be curious to know if Sakai exposes student name as part of it's API... Not sure if this is an industry standard, and not sure if Sakai adheres to those industry standards.
If ever the "Works in all" portion doesn't work as is, try preceding it with the following script:
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);
… and the rest following "...GetPlayer() …"
Hello everybody,
I read every single message in this thread, and in some others.
But couldn't find what I am looking for :
My client LMS (Talentsoft) in SCORM 2004, can display cmi.learner_name as a variable.
I tried many many many syntaxes to grab this data, but I guess the only working one wasn't in my scope !
Can anymone help me ? what is the syntaxt to grab this value ?
thank you for the help
Philippe
Hello again,
Matthew Bibby gave me the answer. It works perfectly in Talensoft LMS.
Be aware that I only needed the firstname.
Here is his code to close my question.
Philippe
Steve,
I doubt you pay any attention to this 7 years later - but I just had to say thanks! I have been racking my head against this keyboard for hours...all I needed was the SCORM_ component to work with the LMS we are using.
So excited!
I have unfortunately been unable to extract any information using many permutations of the code above from the LMS to my Articulate file. I am testing this with LearnDash.
If anyone has a .story file that works published as SCORM 2004 I would love to see it!
Thanks
Hey can any one help,
any idea for custom description/track send to data on LMS through JS.
exammple question are attached
we need report Questions and what user select on lms
advanced thanks
Hey all! I've been using variations of this code for a while now to add my learner's name to in-course instructions and certificates and it's been very useful. Thanks all!
However, I've found that platforms such as Litmos, Docebo, and Cornerstone, tend to add an unwanted space before the first name.
In the past I've worked around this by reducing the left margin on the text box that displays the variable, as I'm not really a coder. But recently I've been 'chatting' with ChatGPT to analyze and refine code.
During a recent chat, ChatGPT provided this updated code. It pulls the user name from the LMS, removes any spaces, and splits it into First Name and Last Name.
And it works!
var player = GetPlayer();
function findLMSAPI(win) {
if (win.hasOwnProperty("GetStudentID")) return win;
else if (win.parent == win) return null;
else return findLMSAPI(win.parent);
}
function removeSpaces(name) {
return name.replace(/\s/g, '');
}
var lmsAPI = findLMSAPI(this);
var myName = lmsAPI.GetStudentName();
if (myName.charAt(0) === ' ') {
myName = myName.substring(1);
}
var array = myName.split(',');
var firstName = removeSpaces(array[1]);
var lastName = removeSpaces(array[0]);
player.SetVar("FirstName", firstName);
player.SetVar("LastName", lastName);
But what if the last name is complex? de Jesus, Von Trapp, Van Gogh??????
That was my concern too - but on my LMS it appears this code parses the name from only the first break. So Brian De Palma is split into Brian and De Palma. As always with Javascript, results may vary but this worked for me on Docebo.
For anyone not using Docebo (which handles complex surnames like De Palma or Van Gogh) , Chat GPT recommended the following amendments to the code:
var player = GetPlayer();
function findLMSAPI(win) {
if (win.hasOwnProperty("GetStudentID")) return win;
else if (win.parent == win) return null;
else return findLMSAPI(win.parent);
}
var lmsAPI = findLMSAPI(this);
var myName = lmsAPI.GetStudentName();
if (myName.charAt(0) === ' ') {
myName = myName.substring(1);
}
var regex = /([^,]+),(.+)/;
var match = myName.match(regex);
var lastName = match[1];
var firstName = match[2];
player.SetVar("firstName", firstName);
player.SetVar("lastName", lastName);
Is anyone able to share a .story file example where it pulls in a users profile photo from an LMS also? The name comes through perfectly but I don't currently don't have the expertise to re-purpose this and pull in a users photo also. Many thanks everyone, this is the best resource community by far.
I don’t see how you can pull in a users photo there is nowhere in the scorm standard for this. It maybe you can pull a unique I’d from thee LMS you can compare against a company database and pull the picture from there, but you would need to use a web object as Storyline variables are finite and a base64 image would be too large.
Sent from my iPhone
Ahh thanks Phil, I asked chat GPT which gave me hope here, this is what it recommended
---------------------
// Get the LMS API object
var lmsAPI = parent.GetAPI();
// Check if the LMS API is available
if (lmsAPI) {
// Get the current user's ID
var userID = lmsAPI.GetStudentID();
// Use the user ID to retrieve the profile photo URL
var profilePhotoURL = getProfilePhotoURL(userID);
// Update the profile photo in the Storyline content
updateProfilePhoto(profilePhotoURL);
} else {
console.error("LMS API is not available.");
}
// Function to retrieve the profile photo URL for the given user ID
function getProfilePhotoURL(userID) {
// Add your code here to retrieve the profile photo URL from the LMS for the given user ID
// Example:
// return "https://example.com/profile-photos/" + userID + ".jpg";
return "";
}
// Function to update the profile photo in the Storyline content
function updateProfilePhoto(profilePhotoURL) {
// Add your code here to update the profile photo in the Storyline content
// Example:
// document.getElementById("profile-photo").src = profilePhotoURL;
}
----------------
If anyone else or even I do get a working version going I'll add to this thread.
A while back, Sam Coulson replied to a request surrounding retrieving data from an LMS. He included the list of variables LMSAPI.js addresses. These are industry-standard variables and functions, originally used by AICC-compliant LMS' and courses.
As Sam says in his message, "this is advanced coder territory, reverse-engineer with caution."
Help with JavaScript and pulling data from an LMS
The SCORM Run-Time Reference Guide describes the data elements supported by the specification. Learner-demographic data (which your LMS may or may NOT support) is confined to:
While AICC does have several more learner-demographic data elements than SCORM does (including address, company, and years of experience), AICC, which SCORM was based on, did not support a data element for the learner's photo.