Forum Discussion
Setting an expiry date for published content
I've done this multiple times in Storyline with JavaScript for clients and it works well. Connect with me on LinkedIn and I'll walk you through it.
Phil is correct that you can use this to [partially] expire a course in Rise. It isn't 100% because of the way progress bookmarking occurs in Rise but it will prevent NEW attendees from accessing an expired course.
Hi Owen- Not sure if you're still within this community, but seeking assistance on getting the Javascript correct to expire a course. Please let me know if you are still able to execute this. Unable to contact you through your ELH profile.
- OwenHolt4 months agoSuper Hero
Yes, I'm still here, and YES, I'm happy to help. :)
- LeslieBucher4 months agoCommunity Member
Great! I downloaded the expirydate Storyline file from this thread but am not well-versed in Javascript and cannot seem to get the JS right in the trigger. It has the following:
var player = GetPlayer();
var currentDate = new Date();
var expiryDate = new Date("January 25, 2016 13:00:00");
if(expiryDate < currentDate){
var expiry = "True";
} else {
expiry = "False";
}
player.SetVar("courseExpired", expiry);Is this what you use?
- OwenHolt4 months agoSuper Hero
Sort of. It is a stripped down version with a hard coded expiration date. I'll walk you through it line by line.
var player = GetPlayer(); <-- this connects to the StoryLine player and suppoets the GetVar and SetVar functions of passing data back and forth between StoryLine and JavaScript
var currentDate = new Date(); <-- This gets the date and time from the computer
var expiryDate = new Date("January 25, 2016 13:00:00"); <-- This is the expiration date. In this example, the course expired years ago. Rather than hard code an expiration date like this buried in the JavaScript, I typically set it in StoryLine in a stored variable named something like "CourseExpiration".
***If you do this, the JavaScript needs to change to pull that date information as shown between the [] (which are NOT part of the code but are used here to separate the option.
*** [var tempDate = player.GetVar("CourseExpiration");
var expiryDate = new Date(tempDate); ]
if(expiryDate < currentDate){
var expiry = "True";
} else {
expiry = "False"; <--These lines evaluate the dates. If the expiration date is before the current date, the course is expired and the variable will be set to True. Otherwise, it will be set to false.
}
player.SetVar("courseExpired", expiry); <-- this is the code to send the expiry status back to StoryLine.
Then, in Storyline, either let the user move forward in the course or jump them to an exit course slide based on the courseExpired variable value in StoryLine.
- LeslieBucher4 months agoCommunity Member
So I read back through the thread and found your original JS. I am confused as to how to set the time/days? Happy to communicate here or you can email me at mailto:lmbucher1513@gmail.com if that's easier. What I am trying to publish is a course that expires after 365 days. I copied and updated what you started with- but not sure what to do in the 4th line for time? TIA.
let player = GetPlayer();
var date1 = new Date(player.GetVar("08/06/2025"));
var date2 = new Date(365);
var elapsedTime = date2.getTime() - date1.getTime();
var elapsedDays = elapsedTime/(1000 * 3600 * 24);
player.SetVar("Days", elapsedDays);
Related Content
- 9 months ago