How to access xAPI/Tin Can LMS variables in JavaScript

Dec 06, 2018

When Storyline 360 publishes a SCORM 1.2 or 2004 package, an entire library of SCORM JavaScript functions are created and can be used inside Storyline (for instance: SCORM_CallLMSGetValue("cmi.core.student_id") will get you the student ID from the LMS). Similarly you can use lmsAPI.GetStudentName() (after initializing the lmsAPI variable, of course) to get the student name from the LMS.

When publishing an xAPI package, there does not appear to be such libraries published, or the functions are much less clear. How would I go about getting the xAPI equivalents of SCORM_CallLMSGetValue("cmi.core.student_id") and lmsAPI.GetStudentName()? I can't seem to find any documentation on this anywhere.

27 Replies
Robert Webbe

Hi Jürgen (master of javascript), 

In the course I'm creating at the moment, I like to use the first name only of a learner. So I thought to add a split in the name variable but this is only working for those users who have one first name. Some of the users have multiple first (and last) names so that's not going to work because there is no logic split point.

In the meantime I found out that when I use "inspect" on the page which is running, I find this in the HTML code:

enrolment_model:{"id":3959527,"user_id":481786,"course_id":63080,"uuid":"831754a1-31a7-46da-afd9-c55486b698ec","course_admin":0,"hashtag":"","points":5,"score":5,"levels_completed":0,"leaderboard_opt_out":0,"streak_score":"0.0","latest_completed_attempt_id":849316,"created_at":"2023-06-12 09:56:35","updated_at":"2023-06-20 08:52:29","completed_at":null,"mandatory":0,"start_at":"2023-06-20 08:52:29","due_date":null,"expires_at":null,"recompletion_start_date":null,"deleted_at":null,"assigned_type":"User","assigned_id":481786,"from_external_provider":0,"requires_recalculate":0,"is_tutor":true,"has_full_game_access":true,"user":{"id":481786,"org_id":1762,"uuid":"494b54d0-9ed5-4f2d-8a98-7f0bb2dbe12b","username":"","sso_id":null,"email":"","fname":"Robert","lname":"Webbe","tag_line":"","summary":"","location":

Do you know a way how to read the fname and lname via javascript?


Jürgen Schoenemeyer

here is a script to split the fname (multiple words) and lname (last single word)

var name = "Max Maria Franz Müller-Lüdenscheidt"

var tmp = name.trim().split(" ")
var lname = tmp.pop()
var fName = tmp.join(" ")

console.log("fname:", fName, "- lname:", lname );

you can test such javascript snippets here