Today a user asked for help with coding to get an expiry date for a certificate slide, see thread
It is a nice use case for the use of both system and user variables, and the use of the mysterious Expression command which is only available in the Advanced Actions dialog box (not as simple action in the Actions tab of the Properties panel). If you are totally new to the use of variables, here are some links:
Workflow described here step-by-step will show how to get the expiry date, 3 years from the present date can be calculated and stored in a user variable. It can of course also be done with JS, but I kept to one advanced action. Since I live in Belgium, I used the date format ‘day/month/year’. It is rather easy to change this to another sequence like the one used by ISO or in the USA. Maybe I’ll post an interactive output, where you can choose the sequence of the 3 parameters. It is also possible to go for another way of presenting the date, but that is not treated here. Insertion in the Learning Interaction ‘Certificate’ is not included neither.
You will be using these system variables, all from the category System information:
- cpInfoCurrentYear: its value is a 4-digit number, at this moment 2019
- cpInfoCurrentMonth: its value is a 2-digit number, still January at this moment, will be 01
- cpInfoCurrentDate: its value is a 2-digit number, for me at this moment it will be 29; it may seem bit confusing that I don’t use cpInfoCurrentDay, but that gives a 1-digit number for the sequence in the week. Monday will result in 2 if t Sunday is considered to be the first day of the week in your OS settings.
You need two user variables (how to create them, see third link in the Introduction ‘Why?’)
- v_year: will be used to calculate the expiry year, which would be 2022 for this user (3 years from now).
- v_date: will have the full date of expiration after the calculations explained later.
The third variable v_choice has been used to offer a choice between the sequence for the date numbers. That is not part of this workflow.
2. Advanced action – creation
You need to create this advanced action, which is non-conditional I will explain each command:
- First Expression calculates the expiry year from the present year (cpInfoCurrentYear) and stores it in the user variable v_year. This is possible since the system variable can be seen by Captivate as a number, and using the mathematical operator +. Result will be of course 2022.
- The mathematical operator becomes here a ‘concatenation’ operator: it will add the string “/” to the day number. Do not forget the quote marks, because / is a mathematical operator. Result after this expression is the text: 29/ which will be stored in v_date
- Another concatenation replaces the value in v_date by 29/01
- Third concatenation results in v_date = 29/01/
- Last expression gives the final result v_date = 29/01/2019
The need for 4 expressions to get to the final value for v_date is due to the fact that the Expression command can have only one operator. You can use the Copy/Paste functionality in the Advanced Actions dialog box to speed up the process.
3. Assign action to Slide On Enter event
Attach the Advanced Action to the On Enter event of the slide, where you need to insert the variable v_date.
How you can insert a variable has been explained in the very first link I posted under ‘Why’.
- Change the Advanced action to present the date in another sequence, like ‘Year/Month/Day’. If you are on CP2017 or later, maybe this blog could help.
- For the fans of conditional actions: try to create a version where the learner can choose the sequence. You’ll need probably another user variable in that case and a multiple decision conditional action.
- Which dangers exist for ‘cheating’ (I am a former professor) in the use case as described here? How would you cope with those dangers?