Forum Discussion
SCORM/xAPI not passing grade to Brightspace (D2L) gradebook
- 10 months ago
Hi
In my attached course, I’ve tried to set the score using the code from above inside a storyline object. This worked for my own scorm test harness, but not in scorm cloud. Not sure why.
I then tried changing tack. I modified the ./scormdriver/scormdriver.js file to emit an event when SetValue is called so that it’s easier to add custom logic. I then added a script block right before the closing </body> tag to the ./scormdriver/indexAPI.html file that detects the lesson_completed state and also sets a score.
<script>
/* custom event handler for SCORM_CallLMSSetValue */
window.addEventListener('lmssetvalue', function(e) {
const {api,key,value} = e.detail;
switch (key) {
case "cmi.core.lesson_status":
if (value == "completed" || value == "passed") {
console.info('heard lesson_status completed or passed, setting score');
// set the score to 100
api.LMSSetValue("cmi.core.score.raw", "100");
api.LMSSetValue("cmi.core.score.min", "0");
api.LMSSetValue("cmi.core.score.max", "100");
console.info(api.LMSCommit(""));
}
break;
}
});
</script>On scorm cloud, the score is set to 100% when the course completes.
Does this help?
Oh interesting! And for others coming after, the CustomEvent you added looks something like:
const ev = new CustomEvent("lmssetvalue", {
bubbles: true,
detail: {
api: SCORM_objAPI,
key: strElement,
value: strValue
}
});
window.ldispatchEvent(ev);