Forum Discussion
How to access xAPI/Tin Can LMS variables in JavaScript
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
- RobertWebbe-404Community Member
@Ben Kanspedos
I've dived into this topic last week and learned that it's not going to work when published to xAPI. There is a trick:
1) Publish your project to SCORM (2004)
2) Publish your project again to xAPI
3) Copy the files from the SCORM output to the xAPI output folder (skip duplicates)
4) ZIP the fileIt's a lot more work but it works. I've send a feature request to Articulate for an option to do this in one run.
I've attached my test (story) file for you.
- Jürgen_Schoene_Community Member
perhaps a variant of my first solution
function parseName( inURL ){
const urlParams = new URLSearchParams(inURL.split("?")[1]);
var name = "unknown";
if( urlParams.has("actor") ){
var actor = JSON.parse( urlParams.get("actor") )
if( "name" in actor ){
name = actor.name;
}
} else {
console.error( "no 'actor' in url: ", urlParams );
}
console.log( "name: " + name );
return name;
}
var url = window.location.href;
var name = parseName( url );
GetPlayer().SetVar("name", name);name = actor.name; <- without [0]
- RobertWebbe-404Community Member
YES, you did it! Thank you very, very much, you're my hero of the day Jürgen! 🙏😀
- RobertWebbe-404Community Member
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":"robert.webbe@vodafoneziggo.com","sso_id":null,"email":"robert.webbe@vodafoneziggo.com","fname":"Robert","lname":"Webbe","tag_line":"","summary":"","location":Do you know a way how to read the fname and lname via javascript?
Thx!
- Jürgen_Schoene_Community Member
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
https://www.programiz.com/javascript/online-compiler/
- RobertWebbe-404Community Member
Thanks again Jürgen, your help is appreciated very much!