Forum Discussion
Expiration date for a course inside Storyline
Hi, Is it possible to set an expiration date for a course inside Storyline so that the SCORM package no longer works after a certain date?
I’d recommend setting the expiration date through the LMS, as this allows the course to be completely inaccessible after a specified date, or to redirect learners to an internal page such as an expiration_notice.html.
While this can be implemented in Storyline, it would require using JavaScript to define an expiration date and then, once that date is reached, display a layer or message indicating that the course content is locked due to expiration.
I’ve attached a simple Story file that demonstrates this functionality. You can test it by adjusting the date values in the code to see how it behaves in your environment.
const expirationDate = new Date('2026-06-12').getTime(); // set exp date const currentDate = new Date().getTime(); const timeDifference = expirationDate - currentDate; if (timeDifference > 0) { const daysRemaining = Math.ceil(timeDifference / (1000 * 60 * 60 * 24)); setVar('daysRemaining', daysRemaining); // storyline var } else { setVar('courseExpired', true); // storyline var }
8 Replies
- PernilleReenberCommunity Member
That is correct, Nedim - I just added const player = GetPlayer(); otherwise it didn't work for me. I've now marked your solution as the solution, thanks
- PernilleReenberCommunity Member
Hi Nedim Silverfire PhilMayor
This works best for me (sorry in danish ;-) ) JavaScript and Storyline. Thank you very much for your input.JavaScript:
const player = GetPlayer(); // Sørg for at få adgang til Storyline player objekt// Sæt udløbsdatoen angivet som år, måned dag åååå-mm-dd
const expirationDate = new Date('2026-06-12').getTime();
const currentDate = new Date().getTime();
// Beregn tidsforskel mellem udløbsdatoen og nuværende dato
const timeDifference = expirationDate - currentDate;
// Deklarer variabel 'daysRemaining' i et passende scope for hele funktionens brug
let daysRemaining = 0; // Initialiser som 0 for sikkerhed
if (timeDifference > 0) {
// Beregn antal dage tilbage indtil udløbsdatoen
daysRemaining = Math.ceil(timeDifference / (1000 * 60 * 60 * 24));
player.SetVar('daysRemaining', daysRemaining); // Opdater Storyline variabel
} else {
// Markér kurset som udløbet
player.SetVar('courseExpired', true); // Opdater Storyline variabel
}
// Tjek gyldighed af kurset baseret på resterende dage
if (daysRemaining > 0) {
// Kursus stadig gyldigt
console.log(`Der er ${daysRemaining} dage tilbage.`);
} else {
// Kursus er udløbet
console.log('Kurset er udløbet.');
// Logik for afslutning eller navigation, fx naviger til en afslutningsside
}
Storyline:- NedimCommunity Member
This solution appears to be based on the script I provided earlier, with small adjustments such as logging variable values to the console. While I believe my original answer could have been marked as the solution, I’m glad it worked and happy that I was able to help.
- PernilleReenberCommunity Member
The problem is that the customer is delivered a SCORM package. And they have rights to use it for, say, one year. If I set it up in the LMS, it doesn't prevent the customer from copying the SCORM package. However, if I set it up with JS in Storyline, the customer can't use the package beyond the expiration date. Many thanks for your help!
- SilverfireCommunity Member
Here's another vote for using the LMS to set the date. In this situation, I've always used the LMS, because if you needed to debug the course, or add things to it, or just to view it, you wouldn't want the JS telling you that you couldn't take it. You'd also limit the ability to show it off in your portfolio. Let the LMS do it.
- NedimCommunity Member
I’d recommend setting the expiration date through the LMS, as this allows the course to be completely inaccessible after a specified date, or to redirect learners to an internal page such as an expiration_notice.html.
While this can be implemented in Storyline, it would require using JavaScript to define an expiration date and then, once that date is reached, display a layer or message indicating that the course content is locked due to expiration.
I’ve attached a simple Story file that demonstrates this functionality. You can test it by adjusting the date values in the code to see how it behaves in your environment.
const expirationDate = new Date('2026-06-12').getTime(); // set exp date const currentDate = new Date().getTime(); const timeDifference = expirationDate - currentDate; if (timeDifference > 0) { const daysRemaining = Math.ceil(timeDifference / (1000 * 60 * 60 * 24)); setVar('daysRemaining', daysRemaining); // storyline var } else { setVar('courseExpired', true); // storyline var }- PhilMayorSuper Hero
I read it that they wanted the scorm package to expire and then extrapolated that to mean they are selling licenses. If that is the case it maybe easier to manage using scorm dispatch on scorm cloud. If not use the LMS or the code Nedim supplied.
- PhilMayorSuper Hero
You could use javascript to lock a course based on a date, it would be relatively simple to get around that but it is the only way I know how.