How to insert current date variable into a "customised certificate slide".

Oct 25, 2016

Hi there,

I have created a certificate looking slide at the end of my course. I have added in variables for the learners name, their score achieved, I am just missing the date variable to be populated automatically. 

I have followed the guide on the link below however it has not worked when I have tested it in a clients LMS (SABA). https://vimeo.com/145579723 

I was just wondering if anyone could offer any assistance on this matter?

29 Replies
Joanne Chen

Hi Mitzi, follow the steps below and you should be able to show the date

  1. Create a text variable called 'SystemDate'
  2. Create a text box for reference to the variable 'SystemDate'
  3. Add a trigger - execute Javascript when timeline starts the certificate looking slide 
  4. Copy and paste the code below in the Script coloumn

var m_names = new Array("January", "February", "March",
"April", "May", "June", "July", "August", "September",
"October", "November", "December");
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth();
var yyyy = today.getFullYear();
if(dd<10) { dd='0'+dd }
var date= m_names[mm]+' '+dd+', '+yyyy;
var player = GetPlayer();
player.SetVar("SystemDate",date);

Ashley Terwilliger-Pollard

Hi John,

Did you publish and upload to your web server or LMS? Testing Javascript locally is one of the known causes for it to not work, and you may want to take a look at the information here in regards to the Javascript best practices as it's not something our team can offer support for. 

John Blum

Hi Ashley,

Thank you for the additional info.  Very helpful!  I had published -- the problem was a typo.

I edited the JavaScript as follows so I could extract the current year which we need for a new corporate standard.

var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
var dateString=month + "/" + day + "/" + year
var player = GetPlayer();
player.SetVar("SystemDate",dateString);
player.SetVar("month",month);
player.SetVar("day",day);
player.SetVar("year",year);

Thank you,

John

Annette Litchfield

Hi everyone,

I have used this javascript for other instances in my courses, but I'm wondering if I could change it to show the year prior? For example for copyrights, we need to update all to 2020 and If I could create a script to auto-populate the year prior to the current day. Any tips how to do that? TIA! 

Walt Hamilton

Use Matthew's code.

If you mean print year day month, change this line:

var date= dd+' '+m_names[mm]+', '+yyyy

to this:

var date= yyyy+' '+dd+' '+m_names[mm]

or year month day, change it to:

var date= yyyy+' '+m_names[mm]+', '+dd

If you want print the year before this year, change this line:

var yyyy = today.getFullYear();

to this:

var yyyy = today.getFullYear()-1;

 

Dwayne Schamp

using the above code:

You'll need to add the variable SystemDate to your course. Then insert a textbox on the slide, and enter:

%SystemDate%

This will allow the SetVar to send the "date" information to your course.

The %<varname>% tells SL that this is a variable reference. You can also use the Insert->Reference item in the tool bar, and then use the variable dialog box to select the variable.

HTH 

Walt Hamilton

For this to work, SL needs to have a variable named SystemDate. Then %SystemDate% will show the contents of the SystemDate variable. Be sure to use a text box, and not a text entry box, or the learner will be able to change it.

 

After it is created, %SystemDate% can be inserted with Insert -> Reference, or you can just type it in, but that is vulnerable to not working if typed incorrectly.

Duane Stitt

Thank you, Chat GPT. Here is the javascript for showing the date three days in the future.

var m_names = new Array("January", "February", "March",
"April", "May", "June", "July", "August", "September",
"October", "November", "December");
var today = new Date();
today.setDate(today.getDate() + 3); // Add three days
var dd = today.getDate();
var mm = today.getMonth();
var yyyy = today.getFullYear();
if (dd < 10) { dd = '0' + dd; }
var date = m_names[mm] + ' ' + dd + ', ' + yyyy;var player = GetPlayer();
player.SetVar("SystemDate", date);