Forum Discussion
Expiration date for a course inside Storyline
- 9 days ago
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 }
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:
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.