Forum Discussion
Setting an expiry date for published content
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.
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-8b6 years agoCommunity Member
Thank you again Owen. I'm in the process of typing up a procedure for my peers. I will most likely send to you to review for accuracy :)
- OwenHolt6 years agoSuper Hero
👍
Related Content
- 10 months ago
- 10 months ago