Skip to: Site menu | Main content

Email Facebook LinkedIn Twitter Google

Blog...

Javascript SCORM API

For anyone that's tried to wade through the mountains of SCORM documentation it can be a little frusrating 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)

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Hi thanks for the api script.

Could you pls. explain how to use this in c# with the scorm.
# Posted By Trip | 10/21/11 2:59 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)
# Posted By Jason Holden | 10/24/11 1:52 PM
@Trip - An additional note: You need to launch your SCORM compliant package from withing 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.
# Posted By Jason Holden | 10/30/11 7:22 PM