Search code examples
scormscorm2004

Should I set cmi.objectives.n.id via Javascript scorm API?


Should I set up cmi.objectives.0.id before I set up, for example, cmi.objectives.0.competition_status?

It's in order to interpret REQ_72.4.3.5: "Since the cmi.objectives.n.id is required to be set first prior to any other objective information, if the SCO attempts to set..."

E.g.:

scorm.setValue('cmi.objectives.0.id', 'obj1'); //?
scorm.setValue('cmi.objectives.0.completion_status', 'completed');

Solution

  • (UPDATED)

    Sorry, for some reason I thought you were discussing interactions, not objectives. My answer has been modified to address objectives.

    Yes, the objective is required to have an ID. You can set the ID via the JavaScript API (SCORM RTE) or via the manifest. The ID must be set before you can perform any other actions on the objective, such as set the completion_status.

    If a SCO is requesting to store objective information, then the SCO is required to set the identifier first (unless it was initialized by another means), prior to any other objective information. Once the cmi.objectives.n.id has a value, the data model element is not allowed to be reset to a different value.

    Page RTE 4-97

    If you aren't sure if the ID is set, you can use JavaScript to see if the objective exists and if it has been assigned an ID.

    Example:

    var obj_count = parseInt(scorm.GetValue('cmi.objectives._count'), 10);
    
    if(obj_count === 0){
    
        //We know for sure no objectives exist in your SCO yet.
        //Try setting the ID
        scorm.SetValue('cmi.objectives.0.id', 'obj1');
    
    }
    
    var id = scorm.GetValue('cmi.objectives.0.id');
    var err = parseInt(scorm.GetLastError(), 10);
    
    if(err == 0 && id == "obj1"){ 
    
        //continue as planned...
    
    } else {
    
        //there is an error or the ID is undefined. Time to troubleshoot.
    
    }
    

    If the ID is set but you still can't set completion_status, you might need to double-check your manifest:

    If the <imsss:objectives> are defined for an <imscp:item> element in the Content Package Manifest, then the LMS is responsible for initializing objective run-time data (cmi.objectives.n.xxx) for the SCO based on the Objective Progress Information referenced and managed for the learning activity. Run-time data related to objectives (cmi.objectives.n.xxx) should not be initialized for an activity’s associated SCO unless an objective ID attribute is defined in the sequencing information (<imsss:primaryObjective> or <imsss:objective>). The objective ID attribute shall be used to initialize the cmi.objectives.n.id value. The number of objectives defined in the manifest dictates the number of objective status information that need to be initialized.