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.
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.
- OwenHolt5 years agoSuper Hero
Answers to your questions and some additional information about the code.
Question:- Yes, that is the name I used for the variable and YES you understand it correctly. A lease that began at the start of the year would be 01/01/2020 or a lease starting today would be 02/10/2020.
- "Valid" will work for the variable name. In my example I think I used "Valid_Days". This is a numeric value and you are, again, exactly right; it represents the number of days from the start that the course is valid (or open) for. For 1 year, you would use 365.
- I called my 3rd variable "Days". This is a value calculated by the JavaScript that represent hw many days have passed since the date stored in the "CreationDate" variable.
How the JavaScript works:
- The 1st thing the script does is create a connection to the StoryLine player and stores it a JS variable labeled "Player". let player = GetPlayer();
- Next, the script pulls the creation date from StoryLine and stores it in a JS variable called date1. var date1 = new Date(player.GetVar("CreationDate"));
- The script then pulls the current date from the computer and stores it in a variable called date2. var date2 = new Date();
- When performing math functions with dates, it is easiest to work with the date as a single numeric value stated in a time value. var elapsedTime = date2.getTime() - date1.getTime(); converts both date variables into a time value in milliseconds and subtracts one from the other.
- The result of the above calculation will be a number in milliseconds representing the difference between the 2 dates so var elapsedDays = elapsedTime/(1000 * 3600 * 24); converts the value back to a number representing days.
- player.SetVar("Days", elapsedDays); sends the value back to StoryLine.
- Once you have the calculated variable, you still need a trigger to compare the value of days that have past versus days the course should be active and display the expired layer if the elapsed time is greater than the allowed time.
See it in action here and download the template from the resources in the published course.
- RachelHorton-8b5 years agoCommunity Member
Hi Owen,
I am just seeing now that you enclosed a Template file. I apologize. I don't know how I missed that earlier. I will give that a look and reach out if I have any further questions. Thank you again!
Rachel
- MacMcElveny2 years agoCommunity Member
Would this allow a content creator to send a SCORM file course to a user without using a delivery system like SCORMCloud? Or would a savvy course purchaser be able to remove this if given a "raw" scorm file?