Forum Discussion
Course completion with a code block?
I know this is an old thread... but with the enhancements that have been made over time to the code block it would be AMAZING to be able to have it as an option for tracking course completion.
Having to add Storyline blocks as well adds more maintenance than necessary to the course.
If you're comfortable with code blocks, it is possible to use the function call John_Reddinger provided. The SCORM API lives "higher up" than the code block so we just have to prepend the call like so:
window.top.SCORM2004_CallSetValue('cmi.completion_status', 'completed');
I just made a quick Rise course with a code block that calls the above function when a button in the code block is clicked, and SCORM cloud registered the completion no problem.
- Justin_H6 days agoCommunity Member
We encountered CORS errors when attempting to access the SCORM API like this in a code block when embedding in our LMS. The below code worked for us instead.
More generally, does anyone know if accessing the SCORM API like this from within a Code Block could be problematic at all? In other words, should we be thinking twice about publishing Rise SCORM packages that use the SCORM API to do things like set the score from within Code Blocks? Is this akin to calling an undocumented API?
I've been trying to find technical documentation that describes how developers can/should interact with the Rise package from within a Code Block. There are some great examples on these forums, but I've not seen any of the more "official" information with guidelines/best practices that I've been expecting.
const findScormAPI = (win) => { let attempts = 0; // Look up/through the window chain for an API object const scanChain = (currentWindow) => { while (currentWindow && attempts < 50) { attempts++; if (currentWindow.API_1484_11) return currentWindow.API_1484_11; if (currentWindow.API) return currentWindow.API; if (currentWindow.parent && currentWindow.parent !== currentWindow) { currentWindow = currentWindow.parent; } else { break; // Reached the top of this window chain } } return null; }; // 1. Search the current window's parent chain console.log("Scanning window parent chain for SCORM API..."); let api = scanChain(win); // 2. Search the opener's parent chain (i.e. for new-window launches) if (!api && win.opener && win.opener !== win) { console.log("API not found in parent chain. Scanning window.opener chain..."); api = scanChain(win.opener); } // Log the final discovery result if (api) { console.log(`API successfully found after ${attempts} total attempts.`); } else { console.log(`API NOT FOUND. Reached ${attempts} attempts limit or top of window chains.`); } return api; }; const api = findScormAPI(window); api.SetValue("cmi.score.raw", "100"); api.Commit();- AndrewBlemings-5 days agoCommunity Member
Definitely much more robust, thanks for sharing!
Related Content
- 11 months ago
- 1 month ago
- 7 months ago