Blog

Javascript SCORM API

June 1, 2011

For anyone that’s tried to wade through the mountains of SCORM documentation it can be a little frustrating trying to put all the pieces together.

This is useful if you want to get interaction data out of products like Adobe Captivate, Adobe Presenter, or Articulate.

So I’m providing a very simple SCORM 2004 javascript API that will hopefully be a useful starting point for anyone trying to implement an LMS or SCORM data collector.

<script type="text/javascript">
	window["API_1484_11"] = {
		Initialize: function(parameter) {
 			console.log("Initialize: parameter=" + parameter);
			return "true";
 		},
		Commit: function(parameter) {
			console.log("Commit parameter=" + parameter);
			return "true";
		},
		Terminate: function(parameter) {
			console.log("Terminate parameter=" + parameter);
			return "true";
		},
		GetValue: function(parameter) {
			console.log("GetValue parameter=" + parameter);
			if (parameter.toLowerCase() == "cmi.completion_status")
				// Default response
				return "incomplete";
			return "";
		},
		SetValue: function(paremter_1,parameter_2)  {
			console.log("SetValue: paremter_1=" + paremter_1 + " | parameter_2=" + parameter_2);
			return "0";
		},
		GetErrorString: function() {
			console.log("GetErrorString");
			return "";
		},
		GetDiagnostic: function() {
			console.log("GetDiagnostic");
			return "";
		},
		GetLastError: function() {
			console.log("GetLastError");
			return "0";
		}				
	};
</script>

This script needs to be on the page that launches the SCORM compliant presentation.

Click here to download a demo presentation (MUST BE LAUNCHED FROM A WEBSERVER / WILL NOT WORK IF LAUNCHED DIRECTLY)

6 Comments

Trip
TripOctober 21, 2011 at 2:59:54 pm

Hi thanks for the api script.

Could you pls. explain how to use this in c# with the scorm.

Jason Holden
Jason HoldenOctober 24, 2011 at 1:52:23 pm

@Trip - I wish I could provide you a good C# example, but unfortunately I'm not well versed in the language. The good news is that the script provided should work with ANY web development platform.

Here's the basics of how it "should" work:
1. You need to output the the script onto the page. I typically do this as a simple <SCRIPT> include in the page header.

<script type="text/javascript" src="my_scorm_api_definition.js">

2. Within the Javascript API methods (SetValue,GetValue,Commit) you need to perform your server interaction magic. I usually put AJAX calls to a webpage that is waiting to accept the data via a standard FORM POST. Making SetValue send the values for parameter_1 and parameter_2. How you achieve the server interaction is completely up to you. I typically approach it like just another AJAX request. In your case perhaps a C# page that processes the request. Here's an example of what your C# "receiving" page might look like (forgive the crudeness):

int loop1;
NameValueCollection coll;

//Load Form variables into NameValueCollection variable.
coll=Request.Form;
// Get names of all forms into a string array.
String[] arr1 = coll.AllKeys;
for (loop1 = 0; loop1 < arr1.Length; loop1++)
{
if (arr1[loop1] == "parameter_1") {
// Do something interesting with the data received like storing it in a database.
}
}

In the end your SCORM Javascript API script should be sending the data to the server as standard form variables (Request.Form).

Hope this helps. If you have some code you'd like for me to look at please feel free to use the contact form on this site to contact me directly (http://www.jasonholden.com/contact.cfm)

Jason Holden
Jason HoldenOctober 30, 2011 at 7:20:17 pm

@Trip - An additional note: You need to launch your SCORM compliant package from within a new popup window or within and IFRAME. The SCORM definition defines how your published content will search for the API variable. Once it has found it, it will automatically begin to call the predefined methods.

Alan
AlanOctober 15, 2012 at 4:24:23 am

Problem with seeing cmi.interactions.
This is a nice example, similar to one I'd been working on. However, I'm having real problems seeing anything from cmi.interactions.
I've created a course in Adobe Presenter v7.0.7 set my reporting to be SCORM 2004 and asked for interactions to be reported.
I can see that I have passed or failed and completion status etc., but I'm expecting to see what answers I entered for the quizzes.
If you have any insight into this I'd love to hear from you.

Jason Holden
Jason HoldenOctober 15, 2012 at 8:07:01 am

@Alan
I'm too familiar with Presenter. I'd be happy to download the trial and try to find the answer if you want to send me your source files. I sent an email to the address you left with the comment if you want to reply to it.

Joe Danziger
Joe DanzigerJanuary 2, 2013 at 9:19:34 am

Hey Jason - thanks for your work on this, it was VERY helpful! Every example I found was related to adding SCORM to courseware.. great to find one that took it on from the LMS side. Kudos!!

I needed a version for SCORM 1.2, but it was very easy to create based on your example and I've included the code below in case anyone else need it:

window["API"] = {
LMSInitialize: function(parameter) {
console.log("LMSInitialize: parameter=" + parameter);
return "true";
},
LMSCommit: function(parameter) {
console.log("LMSCommit parameter=" + parameter);
return "true";
},
LMSFinish: function(parameter) {
console.log("LMSFinish parameter=" + parameter);
return "true";
},
LMSGetValue: function(parameter) {
console.log("LMSGetValue parameter=" + parameter);
if (parameter.toLowerCase() == "cmi.completion_status")
// Default response
return "incomplete";
return "";
},
LMSSetValue: function(paremter_1,parameter_2) {
console.log("LMSSetValue: paremter_1=" + paremter_1 + " | parameter_2=" + parameter_2);
return "0";
},
LMSGetErrorString: function() {
console.log("LMSGetErrorString");
return "";
},
LMSGetDiagnostic: function() {
console.log("LMSGetDiagnostic");
return "";
},
LMSGetLastError: function() {
console.log("LMSGetLastError");
return "0";
}
};

Leave Your Comment

Your email address will not be published. Required fields are marked *


about me

An information technology professional with twenty four years experience in systems administration, computer programming, requirements gathering, customer service, and technical support.