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?
Hi Mitzi, follow the steps below and you should be able to show the date
Create a text variable called 'SystemDate'
Create a text box for reference to the variable 'SystemDate'
Add a trigger - execute Javascript when timeline starts the certificate looking slide
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);
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.
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);
This is a very helpful thread. I was able to correctly add the system date to a certificate I created. However, it appears the user has the ability to edit the date on the certificate slide. Does anyone know how to prevent this? Thank you!
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!
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.
I could not get this to work. What should be in the text box? I cannot have a blank text box. I tried "SystemDate" and "= %system_date%" as placeholder text but nothing worked.
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.
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);
29 Replies
Hi Mitzi, follow the steps below and you should be able to show the date
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);
Thanks for stepping in, Joanne, with your scripting super skillz :)
I tried to use this, but the value of the textbox was a blank space.
I have a blank slide with a textbox containing the text"= %system_date%" was a blank space.
This is the first time I tried using JavaScript in Storyline. don't know why it's not working. Any help would be appreciated.
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.
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
Thanks for the update John :) Glad you were able to get that sorted.
Wow! This is terrific!! THANKS!
That is great, but I don't know Javascript well enough to make it into the Date Month Year format. For example, 14 March, 1962.
I have moved the quotes all around, but I'm not sure which goes where and after 9 tries, I am giving up.
Please help!
Do you know how to make it appear in date/month/year format? For example, 12 September 2020
It worked, Matthew! You are amazing! Thank you so much!
Hi Everyone,
This is a very helpful thread. I was able to correctly add the system date to a certificate I created. However, it appears the user has the ability to edit the date on the certificate slide. Does anyone know how to prevent this? Thank you!
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!
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;
That's for the info!
Is it possible to have the date locked base on when their quiz was completed?
Hi there my date is comes up as false. have i missed a set?
How do I tie the variable to the text box? That is, how do I make the date appear in the box?
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
Thanks, Dwayne! It's a mystery how everyone else already knew this.
Got a challenge for you...
Can you do this system date code plus three days?
I am needing "today's" date to be displayed, plus the date 3 days after "today's"
Is this possible?
Thank you Joanne Chen and others!
I have the same problem right now. I hope there was an answer for this.
I have the same problem right now. I hope there was an answer for this.
I could not get this to work. What should be in the text box? I cannot have a blank text box. I tried "SystemDate" and "= %system_date%" as placeholder text but nothing worked.
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.
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);