Forum Discussion
How to insert current date variable into a "customised certificate slide".
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?
- JoanneChenSuper Hero
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);- VickieSubletteCommunity Member
Do you know how to make it appear in date/month/year format? For example, 12 September 2020
- NatalieBowmanCommunity Member
Hi, this worked for me.
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= ' '+dd+m_names[mm]+', '+yyyy;
var player = GetPlayer();
player.SetVar("SystemDate",date);
Thanks for stepping in, Joanne, with your scripting super skillz :)
- JohnBlumCommunity Member
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.
- JohnBlumCommunity Member
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.
- SylviaWrightCommunity Member
Wow! This is terrific!! THANKS!
- VickieSubletteCommunity Member
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!
- VickieSubletteCommunity Member
It worked, Matthew! You are amazing! Thank you so much!
- MargaretHartofiCommunity Member
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!