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.

11 Replies
Nandhakumar S

Here is Retrieve the username From storyline code.

function getParameterByName(name, url) {

if (!url) url = window.location.href;

name = name.replace(/[\[\]]/g, "\\$&");

var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),

results = regex.exec(url);

if (!results) return null;

if (!results[2]) return '';

return decodeURIComponent(results[2].replace(/\+/g, " "));

}

var a =[];var a1 = [];

var foo = getParameterByName('actor');

a = foo.split(",");

var x=a[0];

a1 = x.split(":");

var str = a1[1];

var UName = str.replace(/[^a-zA-Z ]/g, "");

var player = GetPlayer();

player.SetVar("UserName",UName);

Scott Dellinger

Thanks for the info! I actually figured out that I could get the actor info from the querystring and parsed it all together, however, I'd still like to be able to interact with the LMS variables not available in the querystring, such as the completion status and score. Is there no way to do this in Storyline 360 if you're using Tin Can?

Scott Dellinger

This ended up working for me (this is the "passed" version... I also have a failed version):

var player = GetPlayer();
var iascore = { raw: player.GetVar("FinalPercent"),min:0,max:100 };
var iatc = new TinCan({url: window.location.href});
var stmt = { verb: "passed", inProgress: false, result: { } };
stmt.result.success = true;
stmt.result.score = iascore;
iatc.sendStatement(stmt);

I used a custom variable in Storyline called "FinalPercent" to obtain the Results.ScorePercent and report it back to the LMS.

Nandhakumar S

You can use this code for failed version.

var player = GetPlayer();
var iascore = { raw: player.GetVar("FinalPercent"),min:0,max:100 };
var iatc = new TinCan({url: window.location.href});
var stmt = { verb: "failed", inProgress: false, result: { } };
stmt.result.success = false;
stmt.result.score = iascore;
iatc.sendStatement(stmt);

Kimberly Bold

Can you guys please tell me where you're entering your code?  What file(s)?  I followed the instructions from this example which required updating the Story_html5.html file with the insertion of some test js files that were also provided in the instructions, but would like to know how to execute without the override.  I'm also looking for guidance on the Javascript statement in Storyline to include multiple variables/statements as the above example only included one Verb.  I'm new to xAPI as well as JavaScript, so any assistance is greatly appreciated.  Thanks in advance!!

Steven Pascoe

Hi, can anyone help me? Nandhakumar S code doesn't work quite right.

The Tin Can code works on Scorm Cloud but not on our custom system. We get mailto

Is there any workaround?

This might be occuring because of mbox.

mailto

function getParameterByName(name, url)
{
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
var a =[];var a1 = [];
var foo = getParameterByName('actor');
a = foo.split(",");
var x=a[0];
a1 = x.split(":");
var str = a1[1];

var UName = str.replace(/[^a-zA-Z ]/g, "");

var player = GetPlayer();
player.SetVar("Username",UName);

 

Appreciated!

Rosy Colelli

Hello, I need to pass my score to LMS. I have to publish the course as Tincan. I tried the below Java but doesn't work.... LMS shows Score unknown

var player = GetPlayer(); var passingScore = "75"; function findLMSAPI(win) { if (win.hasOwnProperty("GetStudentID")) return win; else if (win.parent == win) return null; else return findLMSAPI(win.parent); } var lmsAPI = findLMSAPI(this); lmsAPI.SetScore(player.GetVar("Score"), 75, 0); if (player.GetVar("Score")>= passingScore) { SetStatus("passed"); } else { SetStatus("failed"); }

 

Could you help me, please?

Rosy Colelli

Hello, I need to pass my score to LMS. I have to publish the course as Tincan. I tried the below Java but doesn't work.... LMS shows Score unknown

var player = GetPlayer(); var passingScore = "75"; function findLMSAPI(win) { if (win.hasOwnProperty("GetStudentID")) return win; else if (win.parent == win) return null; else return findLMSAPI(win.parent); } var lmsAPI = findLMSAPI(this); lmsAPI.SetScore(player.GetVar("Score"), 75, 0); if (player.GetVar("Score")>= passingScore) { SetStatus("passed"); } else { SetStatus("failed"); }

 

Could you help me, please?