JavaScript for Username (ID number)

Dec 06, 2020

Hello, I want to pull the username (ID) from our LMS (Totara) and have it show in Articulate Storyline 360. I've managed to find (and get working) JS for firstname and surname, but I don't know how to change this so it pulls the username. The username isn't a combination of firstname and surname so I can't just combine the existing JS unfortunately. It's a unique value which sits in the Username field of Totara.

8 Replies
Joseph Francis

If the username is stored in the LMS Student ID field, then you can retrieve it using lmsAPI.GetStudentID();. This calls to the SCORM and AICC data element cmi.core.student_id. If your LMS is using a custom field to store that information, then it will be considerably more difficult to retrieve it.

This list of functions available in the LMSAPI.js file is still relevant, and as the author states, reverse-engineer with caution.

https://community.articulate.com/discussions/articulate-storyline/help-with-javascript-and-pulling-data-from-an-lms

Stacey Craig

Thank you both, but I don't know what I'm doing with JS and need an idiot's guide. I've used this JS to get Student Name:

var lmsAPI = parent;
var name = lmsAPI.GetStudentName();
var nameArray = name.split(", ");
var firstName = nameArray[1];
var lastName = nameArray[0];
var player = GetPlayer();
player.SetVar('first_name',firstName);
player.SetVar('last_name',lastName);

But I don't know how to change it to get StudentID instead. I tried changing var name to say GetStudentID and then changed player.SetVar to 'student_ID'.studentID and then set up a variable called studentID but nothing happened. Can you tell I really have no idea what I'm doing! 

 

Joseph Francis

Using your existing code, add the following 2 lines to the bottom:

var lmsStudent_ID = lmsAPI.GetStudentID();
   player.SetVar("lmsStudent_ID", lmsStudent_ID);

In Storyline, create a new variable called lmsStudent_ID. Open a slide, and from the Insert menu, select Text | Reference. Insert your new variable lmsStudent_ID. Publish your file, upload it to your LMS, and launch it.

Math Notermans

And you might want to add some console.logs or alerts at key points. To see whether you'r code is running fine...or at some point your have errors.

console.log("LMSApi is available "+LMSApi);

console.log("name is: "+name);

or with alerts...
alert("test1");

alert("name is: "+name);

But as said if you dont know Javascript and just copy/paste...well either start learning javascript or share a Storyline file...else you can make hundreds of mistakes. From typos to copying and pasting garbage...