Forum Discussion
Retrieve LMS User Name as Variable
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?
Thx
- AngelaKimCommunity Member
Hi,
We are trying to retrieve two identifiers (numerical IDs) from the LMS to appear at the top of our course. Is there a way to do this with javascript and to appear in HTML5 output of the course when launched from our LMS? Our LMS is CECity. Any help would be appreciated...I don't know a lot about javascript, but this string seems to indicate that this is possible with names from the LMS, so I'm assuming other information can be pulled into the course as well. Thanks!
- AngelaKimCommunity Member
We're trying to create a seamless flow from a platform that will authenticate a user with two identifying numbers ("#######" and "#######") that will manually be entered by the user. Our IS team says that they can create an API call with these numbers...and I assume this API call would be sent to our LMS that will host the course. Once the course is launched from our LMS, we would like those identifying numbers to appear at the top of each slide. We are trying to avoid requiring them to enter that information again within the course in order to accomplish those numbers appearing at the top of each slide for the course.
- AngelaKimCommunity Member
Hm, they're the ones asking me if it's possible to do this in Storyline :( Thanks for your input.
- AngelaKimCommunity Member
Thank you, Mr. Matthew Bibby!!! That would be fantastic. Let me see what they say and get back to you!
- SteveFlowersCommunity Member
Hi Angela -
Depends on how / where it's displayed. When the course launches, if the info is contained in the query string ?value=name, then it's pretty easy to grab.
If the info you want to grab appears in a parent window or frame consistently, it can be scraped with some creative javascript. Try this. You can retrieve your name from the title attribute of the user image in the upper right of the elearning heroes site by adding this to the developer's console:
console.log(document.getElementsByClassName("user__img")[0].getAttribute("title"));
Right-click the window and choose inspect (in Chrome) then click the console tab. Paste that line in there. The same concept applies to anything that appears in a page. You can scrape that data from a displayed page easily. Same concept applies to pages that aren't displayed. You can grab stuff from a page return and chisel little bits of data if the page address is reliable and the "address" of the information within the DOM is predictable.
Anything that appears in a page structure can be grabbed from Storyline as long as the user has access to the page. - LucioCommunity Member
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() …"
- philMekCommunity Member
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
- BrianBland-ClarCommunity Member
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
- Anjumprawez-b02Community Member
- Jonathan_HillSuper Hero
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);- OwenHoltSuper Hero
But what if the last name is complex? de Jesus, Von Trapp, Van Gogh??????
- Jonathan_HillSuper Hero
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.