I am working in Storyline 360 and creating a "certificate" with the User's Name and the date - both being pulled from our LMS. I am unable to get the Username to work. We are publishing to HTML 5- is that the problem?
Add a trigger to execute Javascript inside Storyline
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(); var array = myName.split(','); var newName = array[0]; // you can also try array[1] player.SetVar("VariableName", newName); // VariableName is your Storyline Variable
This is great!! In Exceed LMS, when I set array to 0, it returned the last name. When I set it to 1, it returned the first name.
So I set up two variables: %fname% and %lname% and set two triggers to run that script when the course starts, once with array[0] associated with %lname% and once with array[1] associated with %fname%,
Here it is with the date. (I added a Complete Course trigger because I had to keep re-enrolling myself as I tested when it was completing by slide count...)
(of course uploading a scorm.zip to create a course gets you a "CERTIFICATE" option (et al) on the course's "page" so you don't actually have to do this. But I was like all the way through (except for the name part) and wanted to make it work/ not have wasted my time.
Thank you Daniel and James! This is great to know.
Does anyone know how this would work on Articulate Online (if at all).
I tried it using the story file James had uploaded, but I'm not getting the user name back (first or last). I have a feeling Articulate Online doesn't store the data as 'StudentName' (maybe?).
Shouldn’t I use user ID instead of user’s first and last name? For example, if an organization have 2 or more employees with identical names, it’d be a problem, isn't it? If so, how can I get the user ID from LMS?
If the first and last name fields are blank in the LMS is there a way to replace the empty string with a fixed text, like "Learner" or something? Please excuse my lack of JavaScript knowledge.
Hey all! I've been using 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 Daniel!
However, I've found that platfoms such as Litmos, Docebo, and Cornerstone, tend to add an unwanted space before the first name.
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);
I'm curious how you set this up. Are you saying I can create a Storyline course that will pull the username from my LMS into the published course within the LMS? How is this done? Do you mind sharing the steps you took to accomplish this or at least point me in the right direction? Thanks.
We use Docebo and with hunting/pecking were able to come up with the solution you'll see in the Storyline file. I'm sure Jonathan's ChapGPT is cleaner! And maybe smarter, but well. Here you go! Hope it works for you. The file has instructions and a few examples.
14 Replies
Hi,
Try this Javascript.
Add a trigger to execute Javascript inside Storyline
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();
var array = myName.split(',');
var newName = array[0]; // you can also try array[1]
player.SetVar("VariableName", newName); // VariableName is your Storyline Variable
This is great!! In Exceed LMS, when I set array to 0, it returned the last name. When I set it to 1, it returned the first name.
So I set up two variables: %fname% and %lname% and set two triggers to run that script when the course starts, once with array[0] associated with %lname% and once with array[1] associated with %fname%,
Worked like a charm.
Feel free to test the attached in your LMS.
Here it is with the date. (I added a Complete Course trigger because I had to keep re-enrolling myself as I tested when it was completing by slide count...)
Thank you both so much for sharing!
BRIDGE LMS (and SL 360)
(THUMBS UP!)
(of course uploading a scorm.zip to create a course gets you a "CERTIFICATE" option (et al) on the course's "page" so you don't actually have to do this. But I was like all the way through (except for the name part) and wanted to make it work/ not have wasted my time.
thanks!!
Thanks everyone!!! I just tried this within Success Factors and it worked! Like James, I used "1" which resulted in the first name.
Thank you Daniel and James! This is great to know.
Does anyone know how this would work on Articulate Online (if at all).
I tried it using the story file James had uploaded, but I'm not getting the user name back (first or last). I have a feeling Articulate Online doesn't store the data as 'StudentName' (maybe?).
It works GREAT. Thanks!
Shouldn’t I use user ID instead of user’s first and last name?
For example, if an organization have 2 or more employees with identical names, it’d be a problem, isn't it?
If so, how can I get the user ID from LMS?
If the first and last name fields are blank in the LMS is there a way to replace the empty string with a fixed text, like "Learner" or something? Please excuse my lack of JavaScript knowledge.
Hi everyone!
Is there a way to insert the learner name and/or the current date without JavaScript?
Thanks!
Hey all! I've been using 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 Daniel!
However, I've found that platfoms such as Litmos, Docebo, and Cornerstone, tend to add an unwanted space before the first name.
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);
Jonathan,
I'm curious how you set this up. Are you saying I can create a Storyline course that will pull the username from my LMS into the published course within the LMS? How is this done? Do you mind sharing the steps you took to accomplish this or at least point me in the right direction? Thanks.
Hi Christopher,
We use Docebo and with hunting/pecking were able to come up with the solution you'll see in the Storyline file. I'm sure Jonathan's ChapGPT is cleaner! And maybe smarter, but well. Here you go! Hope it works for you. The file has instructions and a few examples.
The post may be 5 years ago, but I just tested it in Workday 2024 and it pulled the first and last name of the learner perfectly. Thank you Reference:
This is great!! In Exceed LMS, when I set array to 0, it returned the last name. When I set it to 1, it returned the first name.