Forum Discussion
Setting an expiry date for published content
there are some errors in the story provided by Garth on date validation, when validating date you cannot simply compare each expire value (year, month and day) to actual one, while you must proceed first comparing year, then month, and finally day.
here is a story file that should work well.
I put 2 layers to display the result of validation on each one.
expire date is set in JS but you could also set it by system variable and retrieve those variable when executing the JS.
- BjWilson9 years agoCommunity Member
Thank you for this it works great for CD and web and upgrades to version 2 well
- RachelHorton-8b6 years agoCommunity Member
Hi Zio,
Thank you for sharing your solution. I had it working in past versions of SL. It stopped working. Any ideas as to why?
When the "yearexpire" is set in the future I receive the Valid Layer as designed.
When the "yearexpire" is set in the past, I do not receive the Expired Layer.
Are you still using Storyline? Which version? I am using Storyline 360 v3.34.20804.0.
Any help would be much appreciated.
Thank you.
Rachel- OwenHolt5 years agoSuper Hero
Let me simplify the process and code for you.
You need 3 variables:
- 1 text for a "published" or "created" date in the format of mm/dd/yyyy
- 1 number variable for the number (in days) that the course is valid for, like 60 or 365
- and one numeric variable (let's call it "Days") that will receive a value from the JavaScript below showing how much time has passed sine the course was published/updated
You need to execute the following JavaScript at TimeLine start on your first slide.
let player = GetPlayer();
var date1 = new Date(player.GetVar("CreationDate"));
var date2 = new Date();
var elapsedTime = date2.getTime() - date1.getTime();
var elapsedDays = elapsedTime/(1000 * 3600 * 24);player.SetVar("Days", elapsedDays);
Lastly, you need a trigger to run AFTER the Javascript to show your "Course Expired" layer. It should be something like Show layer Expired when timeline starts if Days > Valid_Days
You can see it in action here: Link to Demo
If that is what you you are looking for, there is a Template file in the resources of the published course that you can download.
- RachelHorton-8b5 years agoCommunity Member
Thank you Owen. I wish I could say I understand completely. I have a few questions.
The outcome I want is to have the expired layer display upon expiration of the content lease which is typically 1 year/365 days.
1. I created a text variable with the name "CreationDate". Is this the correct name I should use? Would the date be the date the lease starts? For example, if the lease begins today I would enter 02/10/2020.
2. I created a number variable with the name "Valid". I entered the Default Value as 365. Is that correct?
3. I don't know what the 3rd variable should look like. What should the Name be? Is it a number variable? Does it need to be a variable name that is already part of the javascript? What is the default value?
I've attached a test course which includes the variables and triggers. I have the Show Layer Expired trigger built. However, I don't know what to add for the Conditions.