SCORM API Wrapper [JavaScript]

Current version: 1.1.7 (May 19, 2008)

  • Download: The wrapper and all example files have been moved to the downloads page.

Having a problem with the wrapper or example files? Visit the eLearning Technology and Development Google Group

Changes

Here’s a list of the changes I made to the ADL wrapper:

  1. Used object notation to faux-‘namespace’ the SCORM wrapper. This means there is only ONE global variable, the pipwerks object. Every other variable and function contained in the wrapper has been moved into the SCORM child object: pipwerks.SCORM.
  2. Cleaned up the code, simplifying where possible, formally declaring all variables, and making the code more consistent (trying to implement modern JavaScript ‘best practices’). The code has been vetted by Douglas Crockford’s notoriously finicky JSLint (with the ‘Assume a browser’ and ‘Tolerate sloppy line breaking’ options enabled).
  3. Renamed variables and functions to more understandable/obvious terms.
  4. Added consistent checks for valid server and API connection before performing most actions.
  5. Added clearly written debugging statements to every function (including just about every if/else clause).
  6. Converted all ‘boolean strings’ returned from the LMS (“true”, “false”) to actual booleans. This aids in error-checking and helps simplify the code.
  7. Converted the GetLastError integer ‘string’ to an actual integer. This aids in error-checking and helps simplify the code.
  8. Added support for both popular flavors of SCORM (1.2 and 2004). This single wrapper file wrapper works with both versions, with no extra configuration required. UPDATE: Some users find it helpful to specify the SCORM version manually. Just add the line pipwerks.SCORM.version = "1.2" (or 2004) before making the pipwerks.SCORM.init() call.
  9. Replaced the ADL’s FindAPI and GetAPI functions with a modified version of Mike Rustici’s FindAPI/GetAPI functions. I modified Mike’s code to be a little more legible, with no global variables, more error checking, debugging messages, and support for both SCORM 1.2 and 2004 in a single file.
  10. Added functionality that automatically handles the initial course status (sets to incomplete upon launch) and handles the course exit status (sets to suspend if course hasn’t been completed yet).

Relationships/Mapping

This table outlines the basic relationships of the SCORM API with the SCORM wrapper object.

Wrapper function SCORM 1.2 Equivalent SCORM 2004 Equivalent
pipwerks.SCORM.init() API.LMSInitialize(“”) API.Initialize(“”)
pipwerks.SCORM.quit() API.LMSFinish(“”) API.Terminate(“”)
pipwerks.SCORM.get() API.LMSGetValue(parameter) API.GetValue(parameter)
pipwerks.SCORM.set() API.LMSSetValue(parameter, value) API.SetValue(parameter, value)
pipwerks.SCORM.save() API.LMSCommit(“”) API.Commit(“”)
pipwerks.SCORM.debug.getCode() API.LMSGetLastError() API.GetLastError()
pipwerks.SCORM.debug.getInfo(errorCode) API.LMSGetErrorString(errorCode) API.GetErrorString(errorCode)
pipwerks.SCORM.debug.getDiagnosticInfo (errorCode) API.LMSGetDiagnostic(errorCode) API.GetDiagnostic(errorCode)

Methods and properties

Here is a list of all of the methods(functions) and public properties (variables) contained in the wrapper.

Last updated May 25, 2008.

Wrapper method or property Notes
pipwerks.SCORM.version String. Stores SCORM version. Is set automatically by wrapper based on API returned from LMS, but can also be set manually.
pipwerks.SCORM.handleCompletionStatus Boolean, defaults to true. Controls whether or not the wrapper will automatically set the initial completion status
pipwerks.SCORM.handleExitMode Boolean, defaults to true. Controls whether or not the wrapper will automatically set the exit mode upon course exit.
pipwerks.debug.isActive Boolean, defaults to true. Controls whether or not the wrapper will use debug statements.
pipwerks.SCORM.init() Arguments: None.

Returns: Boolean indicating success.

Creates the SCORM API connection, initiating your SCORM course session.

Must be invoked by your course code, and must be invoked before calling any other SCORM functions.

pipwerks.SCORM.quit() Arguments: None.

Returns: Boolean indicating success.

Closes the SCORM API connection, terminating your SCORM course session.

Must be invoked by your course code. No other SCORM functions should be called after this.

pipwerks.SCORM.get(param) Arguments: Name of CMI element.

Returns: String (value of CMI element).

Gets the specific parameter from the LMS (returns a string).

Example (SCORM 1.2):

var bookmark = pipwerks.SCORM.get("cmi.core.lesson_location");

Example (SCORM 2004):

var bookmark = pipwerks.SCORM.get("cmi.location");

Must be invoked by your course code.

pipwerks.SCORM.set(param, value) Arguments: Name of CMI element, value to set in CMI element.

Returns: Boolean indicating success.

Sets the specific parameter in the LMS (returns a boolean indicating success).

Example (SCORM 1.2):

var success = pipwerks.SCORM.set("cmi.core.lesson_location", "page2");

Example (SCORM 2004):

var success = pipwerks.SCORM.set("cmi.location", "page2");

Must be invoked by your course code.

pipwerks.SCORM.save() Arguments: None.

Returns: Boolean indicating success.

Instructs the LMS to “persist” the data you’ve sent it.

Some LMSs cache data and don’t immediately write it to the database. It’s a good idea to invoke pipwerks.SCORM.save() whenever you send important data to the LMS; this ensures the LMS has written the data to the database.

For instance, if you send a bookmark via lesson_location, then close your browser window, you can’t be sure if the LMS has written the bookmark data to the database.

If you send the bookmark, then call pipwerks.SCORM.save() before closing the window, you can be reasonably sure your data has been saved to the DB.

pipwerks.SCORM.status(action, status) Internal function that can either retrieve or set the course status stored in the LMS. Can also be used by course developers. Examples:

var status =
pipwerks.SCORM.status(“get”);

var success = pipwerks.SCORM.status(“set”, “completed”);

Is compatible with SCORM 1.2 & SCORM 2004.

pipwerks.SCORM.isAvailable() Returns boolean true.

Used by the pipwerks SCORM ActionScript classes (via ExternalInterface) to verify presence of the wrapper.

pipwerks.SCORM.API.find(window) Used internally to locate the SCORM API exposed by the LMS. You will never need to use this function yourself.
pipwerks.SCORM.API.get() Used internally to locate the SCORM API exposed by the LMS. You will never need to use this function yourself.
pipwerks.SCORM.API.getHandle() Used internally to locate the SCORM API exposed by the LMS. You will never need to use this function yourself.
pipwerks.SCORM.debug.getCode() Gets the last error code from the LMS, indicating success or failure of the the last action.

The wrapper uses this function internally to ensure successful communication between the LMS and course.

You may also invoke this function yourself if you’d like to add an extra layer of error-checking.

pipwerks.SCORM.debug.getInfo(errorCode) Gets a text-based description of a particular error code.

The wrapper uses this function internally to ensure successful communication between the LMS and course.

You may also invoke this function yourself if you’d like to add an extra layer of error-checking.

pipwerks.SCORM.debug.getDiagnosticInfo (errorCode) If an LMS vendor has supplied additional error messages, you would use getDiagnosticInfo the same way you’d use getInfo() to retrieve the message.

The wrapper uses this function internally to ensure successful communication between the LMS and course.

You may also invoke this function yourself if you’d like to add an extra layer of error-checking.

pipwerks.UTILS.trace(msg) Sends debugging messages to the Firebug console.

Used internally throughout the wrapper, but may also be used by your own code. Feel free to edit this portion of the wrapper to handle the messages differently, such as writing them to the HTML page or using the ‘alert’ function.

pipwerks.UTILS.StringToBoolean(string) Used internally to convert ‘boolean strings’ returned by the LMS to actual booleans, such as converting "false" to false.

Naming shortcuts

You may find it easier to work with a ‘shortcut’ name such as scorm or sco instead of the full pipwerks.SCORM. Here’s an example:

//Using pipwerks namespace, SCORM 1.2

var success = pipwerks.SCORM.init();

if(success){
  var status = pipwerks.SCORM.get("cmi.core.lesson_status");
  if(status != "completed"){
    success = pipwerks.SCORM.set("cmi.core.lesson_status", "completed");
    if(success){
       pipwerks.SCORM.quit();
    }
  }
}
//Using shortcut instead of pipwerks namespace, SCORM 1.2

var sco = pipwerks.SCORM;
var success = sco.init();

if(success){
  var status = sco.get("cmi.core.lesson_status");
  if(status != "completed"){
    success = sco.set("cmi.core.lesson_status", "completed");
    if(success){
       sco.quit();
    }
  }
}

Just remember that if you stick to the pipwerks namespace you can be reasonably sure you won’t have any naming conflicts. If you decide to use a naming shortcut, be sure to use something that won’t conflict with any of your other scripts.

LMS compatibility

The example files have been successfully tested on a variety of LMSs. If you’ve tested the files on an LMS not listed here, please let me know!

LMS SCORM 1.2 Example SCORM 2004 Example Notes
ADL Test Suites Works as intended (v1.1.5) Works as intended (v1.1.5) SCORM 1.2 Conformance Test Suite v1.2.7

SCORM 2004 3rd Ed. Conformance Test Suite v1.0.2

SumTotal TotalLMS 7.6 Works as intended (v1.1.4) Works as intended (v1.1.4)
Moodle 1.8 Works as intended (v1.1.4) Works as intended (v1.1.4)
Ilias 3.9.3 Works as intended (v1.1.4) Works as intended (v1.1.4) Ilias loads SCORM 1.2 courses using the SCORM 2004 RTE and the ADL SCORM 1.2-2004 wrapper.
Pathlore 6.5 Works as intended* (v1.1.4) Works as intended* (v1.1.4) As reported by email. Have not verified.

New SCORM ebook coming soon!

I'm writing an ebook explaining how to build an HTML-based SCORM course. Subscribe to be notified when it's ready, as well as receive early bird pricing and some free goodies!

No spam, no sharing your email address, unsubscribe at any time. Powered by ConvertKit
Advertisements

7 Replies to “SCORM API Wrapper [JavaScript]”

  1. Hello Philip,
    I’ve just used your excellent wrapper (1.1.7) and SCORM class (AS3) on the IMC Clix LMS and it worked perfectly. SCORM 2004. Not sure of Clix version I’m afraid. Client installed last year so should be recent.

    I used my own code not your example but I called connect, get, set, save and disconnect.

    Just wanted to say thanks and to add another LMS to the list if you want.

    Cheers,
    Patrick

  2. Hello,

    Thanks for posting very useful information. I am using Flex Builder with 3.5 sdk. I was able to use your clas SCORM class (AS3) and Javascript Wrapper. When I update cmi.suspend_data and I do scorm.save(), the communication log shows it issued a LMSCommit command with my cmi.suspend_data string. I closed the browser and relaunch the content, the data saved wasn’t there. I only way that I can see my data saved is by issuing a scorm.disconnect() in my Flex’s AS3 script. I am working with SABA 5.5 LMS.

    Thanks,
    Phong

  3. Nevermind ..Found my stupid problem 🙂 I had to turn off Debug that was defaulted ON, in the Javascript Wrapper.

    pipwerks.debug = { isActive: false };

    Thanks

  4. Hello I’m using your SCORM API Wrapper for a SCORM 1.2 small course.
    But When run the Content Package Conformance Test v 1.2.7 I got an error in the SCO Run-Time Environment Test:

    ERROR: LMS was ALREADY initialized
    ERROR: Invalid call to LMSInitialized()

    My Course is very simple.
    Is about homepage and 2 modules. Each one is a SCO.

    The Javascript is in only in homepage, and every time I run the SCO test the first module to be launch is Module II.

    When that happens I clic on the home link, the scripts run, then I return to module II clicking on a link, then again I return to homepage and the error appears.

    How can a learner navigate through the course get back and forward through the Course without this error?

    Thank you for your time!
    Great blog, please keep posting.

Comments are closed.