/
SCORM JS API Reference

SCORM JS API Reference

The SCORM API is slightly different than the standard in that there is a javascript layer that calls the controller (MarineLMS-SCORM-API.js).  The controller endpoints are still documented as of version 4.0, available on the API help page (e.g. https://demo.marinels.com/help), however these are not directly called, except by the aforementioned .js file.  

For versions before 4.0 the following can be used as reference (however not all of the endpoints have been implemented/tested):

Base Functions

LMSCommit() - Not Implemented?

Inputs: None
Returns: None

Description: Call the LMSCommit function

LMSFinish()

Inputs: None
Returns: CMIBoolean true if successful
               CMIBoolean false if failed.

Description:
Close communication with LMS by calling the LMSFinish function which will be implemented by the LMS

LMSGetLastError()

Inputs: None
Returns: The error code that was set by the last LMS function call

Description:
Call the LMSGetLastError function

LMSGetErrorString(errorCode)

Inputs: errorCode - Error Code
Returns: The textual description that corresponds to the input error code

Description:
Call the LMSGetErrorString function

  • 0     - No Error
  • 101 - General Exception
  • 201 - Invalid Argument Error
  • 202 - Element cannot have children
  • 203 - Element not an array. Cannot have count.
  • 301 - Not initialized
  • 401 - Not implemented error
  • 402 - Invalid set value, element is a keyword
  • 403 - Element is read only
  • 404 - Element is write only
  • 405 - Incorrect Data Type

LMSGetDiagnostic(errorCode)

Inputs: errorCode - Error Code(integer format), or null
Returns: The vendor specific textual description that corresponds to the input error code

Description:
Call the LMSGetDiagnostic function

LMSGetValue(name)

Inputs: name - string representing the cmi data model defined category or element (e.g. cmi.core.student_id)
Returns: The value presently assigned by the LMS to the cmi data model element defined by the element or category identified by the name input value.

Description:
Wraps the call to the LMS LMSGetValue method

LMSInitialize()

Inputs: None
Returns: CMIBoolean true if the initialization was successful, or
                CMIBoolean false if the initialization failed.

Description:
Initialize communication with LMS by calling the LMSInitialize function which will be implemented by the LMS. This function also gets the SCO id by grabbing the last token of the path in the iframe and adds it to the SCOIDMapping object.

LMSSetValue(cmiElementName, value)

Inputs: cmiElementName -string representing the data model defined category or element
             value -the value that the named element or category will be assigned
Returns: CMIBoolean true if successful
CMIBoolean false if failed.

Description:
Wraps the call to the LMS LMSSetValue function

ValidateInput(cmiElementName)

Inputs: cmiElementName
Returns: none

Description:
Check input to see if it fits the convention for cmi Element Names

ValidateInitialize()

Inputs: None
Returns: False if LMS not initialized
                Else return true

Description:
Check if LMS has been initialized. Return error if LMS has not been initialized. Else return true

Getters

GetLessonStatus (coursePath, shortId, studentId)

Inputs: coursePath -> course path,
             shortId -> identificator
             studentId -> student Guid
Returns: lesson status if correctly stored

Description: Assessment Short Id = SCO.Id + "-Status", stored in the UsersTotal property of the student result audit state

GetObjectiveChildren()

Inputs: none
Returns: objective children

Description: get objective children always returns "id,score,status"

GetObjectiveShortId(coursePath, shortId, studentId)

Inputs: coursePath -> course path,
             shortId -> identificator (SCO.Id + '.' + n)
             studentId -> student Guid
Returns: shortId  (cmi.core.score.n.id?)

Description: Defines assessment name for objective 'n' (needs to be held as state in API object)

GetObjectiveCount()

Inputs: none
Returns: objective children count

Description: get objective children count returns the number of objective level assessments stored for this objective ("-Score" and "-Status" only count as 1)

GetOutOf(coursePath, shortId, studentId)

Inputs: coursePath -> course path,
             shortId -> identificator
             studentId -> student Guid
Returns: outOf if correctly stored (cmi.core.score.max)

Description: Assessment name = SCO.Id + "-Score", stored in the OutOf property of the student result audit state

GetSCOEntry (coursePath, SCOId, studentId)

Inputs: coursePath -> course path,
             SCOId -> identificator
             studentId -> student Guid
Returns: the SCO Data or empty string if none exists

Description: Initializes the SCO Entry if none exists then returns an empty string. Actually more of a CreateOrUpdate (poor naming)

GetSCOTotalTime (coursePath, SCOId, studentId)

Inputs: coursePath -> course path,
            SCOId -> identificator
            studentId -> student Guid
Returns: Gets the total time for the SCO Entry

Description: Gets the total time for the course for the student result audit based on the course path, SCO id, and student id (Guid)

GetSCOLessonLocation(coursePath, SCOId, studentId)

Inputs: coursePath -> course path,
            SCOId -> identificator
            studentId -> student Guid
Returns: Gets the lesson location from the SCO data (cmi.core.lesson_location - r/w opaque field.)

Description: Lesson location as string.

GetSCOSuspendData (coursePath, SCOId, studentId)

Inputs: coursePath -> course path,
            SCOId -> identificator
            studentId -> student Guid
Returns: Get the store SCO Entry data

Description: Gets the saved state of the SCO session, so the user can continue where they left off.

GetSCOComments (coursePath, SCOId, studentId)

Inputs: coursePath -> course path,
            SCOId -> identificator
            studentId -> student Guid
Returns: the comments from the SCO Data (cmi.comments - r/w data from user)

Description: The comments for the course

GetStudent()

Inputs: arguments - properties that should be returned (if no args define then return entire user)
Returns: current user props (format: prop1, prop2, prop3, ...)

Description: gets the current user props

GetUsersTotal(coursePath, shortId, studentId)

Inputs: coursePath -> course path,
             shortId -> identificator
             studentId -> student Guid
Returns: userTotal if correctly stored (cmi.core.score.raw)

Description: Assessment Short Id = SCO.Id + "-Score", stored in the UsersTotal property of the student result audit state

Setters

SetLessonLocation(coursePath, SCOId, studentId, value)

Inputs: coursePath -> course path,
            SCOId -> identificator
            studentId -> student Guid
            value - lesson location
Returns: true if correctly stored otherwise false

Description: Sets location of a lesson (cmi.core.lesson_location) 

SetLessonStatus(coursePath, shortId, status)

Inputs: coursePath -> course path,
            shortId -> identificator
            status ->  The current status of the SCO Entry (see description)
Returns: true if correctly stored otherwise false

Description: Assessment Short Id = SCO.Id + "-Status", stored in the UsersTotal property of the student result audit state.  Statuses:

0 - Failed
1 - Not Attempted
2 - Browsed
3 - Incomplete
4 - Completed
5 - Passed

SetOutOf(coursePath, shortId, outOf)

Inputs: coursePath -> course path,
            shortId -> identificator
            outOf - OutOf value (cmi.core.score.max)
Returns: true if correctly stored otherwise false

Description: Assessment name = SCO.Id + "-Score", stored in the OutOf property of the student result audit state.

SetSCOSuspendData (coursePath, SCOId, studentId, value)

Inputs: coursePath -> course path,
             SCOId -> identificator
             studentId -> student Guid
             value - The data to set 
Returns: true if correctly stored otherwise false

Description: Sets SuspendData (cmi.suspend_data)

SetSCOExit (coursePath, SCOId, studentId, value)

Inputs: coursePath -> course path,
             SCOId -> identificator
             studentId -> student Guid
             value - The data to set 
Returns: true if correctly stored otherwise false

Description: Sets exit (cmi.core.exit)

SetSCOSessionTime (coursePath, SCOId, studentId, value)

Inputs: coursePath -> course path,
             SCOId -> identificator
             studentId -> student Guid
             value - The data to set 
Returns: true if correctly stored otherwise false

Description: Sets session time (cmi.core.session_time) 

SetSCOComments (coursePath, SCOId, studentId, value)

Inputs: coursePath -> course path,
             SCOId -> identificator
             studentId -> student Guid
             value - The comments to set
Returns: true if correctly stored otherwise false

Description: Sets comments (cmi.core.comments) 

SetStudent(prop, value) - TODO verify return

Inputs: prop - property to be set
             value - property value
Returns: sets the student if correctly stored, otherwise returns false

Description: Sets Student's property

SetUsersTotal (coursePath, shortId, newScore)

Inputs: coursePath -> course path,
            shortId -> identificator
            newScore - UsersTotal (cmi.core.score.raw) 
Returns: true if correctly stored otherwise false

Description: Assessment Short Id = SCO.Id + "-Score", stored in the UsersTotal property of the student result audit state

Helper Functions

callServer(url, method, hasBoolResult, params)

Inputs: url - API url,
            method - GET or POST,
            hasBoolResult - if the caller wants to a 'true' or 'false' return, or a result or an empty string?? 
            params - object that represents parameters that need to be sent to server
Returns: response or empty string '' if error happend

Description: calls server API methods (wrapper for Jquery ajax call)

clearError()

Inputs: none
Returns: none

Description: Clears the values of the members of the API.private object

findId(storeName, n)

Inputs: storeName - storage name
            'n' variable
Returns: undefined

Description: Tries to find id/n combination by 'n' variable in specific local storage (Can be multiple, for example interactions or objectives).

getChildrenFromServerResults(results)

Inputs: results - data array from server
Returns: SCORM definition of children objects (always returns "id,score,status")

Description: Map server children objects to SCORM children objects

parseCmi(cmiElementName, value)

Inputs: cmiElementName - cmi name
             value - value to be set
Returns: true if correctly stored otherwise false
Description: Parse cmiElementName to be able to define shortId. (Specs: COREDEV-1219 - Getting issue details... STATUS ) Regular expressions is used for getting group name and modify cmi string for switch statement because the cmi contains value of 'n' variable.

parseShortId(shortId)

Inputs: shortId - shortId that contains id/n
Returns: object that constains property: id, n

Description: Parses shortId string to get property: id & n

setError(SCORMErrorCode, statusCode, Message, StackTrace)

Inputs: SCORMErrorCode
             statusCode
             Message
             StackTrace
Returns: none

Description: sets API.private member variables to the specified error values

storeId(storeName, shortId)

Inputs: storeName - storage name
             shortId - server side shortId that contains information about id and 'n' variable
Returns: undefined

Description: Stores id / 'n' combinations for preventing too many server requests. There can be multiple storages (objectives, interactions).

Error Codes Explained


No error (0) No error occurred, the previous API call was successful.
General Exception (101) No specific error code exists to describe the error. Use LMSGetDiagnostic for more information.
Invalid argument error (201) Indicates that an argument represents an invalid data model element or is otherwise incorrect.
Element cannot have children (202) Indicates that LMSGetValue was called with a data model element name that ends in “_children” for a data model element that does not support the “_children” suffix.
Element not an array. Cannot have count. (203) Indicates that LMSGetValue was called with a data model element name that ends in “_count” for a data model element that does not support the “_count” suffix.
Not initialized (301) Indicates that an API call was made before the call to LMSInitialize.
Not implemented error (401) The data model element indicated in a call to LMSGetValue or LMSSetValue is valid, but was not implemented by this LMS. SCORM 1.2 defines a set of data model elements as being optional for an LMS to implement.
Invalid set value, element is a keyword (402) Indicates that LMSSetValue was called on a data model element that represents a keyword (elements that end in “_children” and “_count”).
Element is read only. (403) LMSSetValue was called with a data model element that can only be read.
Element is write only (404) LMSGetValue was called on a data model element that can only be written to.
Incorrect Data Type (405) LMSSetValue was called with a value that is not consistent with the data format of the supplied data model element.