Forum Discussion
Getting User Name from LMS into Storyline
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);
- ChristopherC6483 years agoCommunity Member
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.
Related Content
- 10 months ago
- 11 months ago