Although Articulate does not provide support for JavaScript coding in the Execute JavaScript trigger, you can accomplish that by using the example in the link below:
I've been thinking of a simple way of inserting an expiry date into a standalone presentation (I mean one that is not within an LMS).
Example application - if I made a sample presentation and emailed it out, but I wanted to prevent it being viewed past a certain date.
I haven't come across any way yet, so I wonder if this method could be used to do that - by coding in the 'currentdevelopment date' into the javascript that Brian demonstrated....and then if I only wanted the presentation to be viewable for the next 2 months say, I would make a sum that took the 'user system date' minus 60, and if it was positive, jump to a branch that ended the presentation (as it was being viewed more than 2 months in the future).
Does that sort of make sense? Sorry, if I've missed a really simple way of achieving the same thing - just haven't found a way yet!
Berno, That did the trick. I had seen this before with "Print Results". I couldn't test it on my local computer before posting to our website, but once posted it worked. Thank you so much! Now I can test these things before I post.
This should work great - I have to simulate a button that inserts todays date and this should do it. As I only want the date to appear when they press the buton i will just do a trigger to change the state to make it 'appear'.
I have tried many different things trying to get your variables working. I thought maybe it was my project causing a glitch, so I started a new project with a blank slide just like your tutorial (I have watched now about 30 times). But still no success. I can not figure out what I am doing wrong. Any help? Attached is the blank slide for your reference.
Hi Daniel and Welcome to E-Learning Heroes! So, are you good-to-go now, or did you still have a question. Just want to be sure that I have not missed anything. Thanks so much and have a great day!
Could anyone (or Brian) please tell me how to modify Brian's javascript so that I can get the current date minus x number of days. The script needs to recognize that the result has to be an actual date; not a negative number. So, if it's only 12/3/2013, subtracting 5 days shows 12/28/2013, NOT 12/-2/2013.
Here's the script which works to get today's date:
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);
Also, just to add to what Michael is saying, most browsers will not run the JavaScript when you run the course locally on your PC. To test properly you have to upload the course to a web server or LMS.
To back up what Nancy said, if you aren't ready to upload to your LMS or web server yet, you could look at testing it out at tempshare.articulate.com or using Amazon S3 as a web server. The directions here will walk you through how to set up an Amazon S3 account.
but I am struggling a little to display the day as "01" and not just "1".
Solutions?
My current javascript command reads:
var m_names = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
var currentTime = new Date(); var month = currentTime.getMonth() + 1; var day = currentTime.getDate();
var year = currentTime.getFullYear(); var dateString=day + "/" + m_names[month] + "/" + year; var player = GetPlayer(); player.SetVar("systemdate",dateString)
I am working on an elearning and need to display a date based on the next available day. The scenario I am working with is a lawyer is only available on Tuesdays for a meeting. If the user taking the module on Thursday 07/15/2021 the date I need displayed in the module would be 07/20/2021.
Is this possible using Javacoding? If so, could someone help me with how the code would need to be written?
23 Replies
Hi Raymond,
Although Articulate does not provide support for JavaScript coding in the Execute JavaScript trigger, you can accomplish that by using the example in the link below:
http://www.articulate.com/support/kb_article.php?product=st1&id=llwes8cn32vg
Hey Brian, thanks for the tip....
I'm not too familiar with Java though...i've tried reviewing your job aids but can't get a date to appear on a slide.
Any way you could take a moment to walk me through it?
Do I need to have a trigger in place in order to have a date appear on the slide?
Apologies....
Hi Raymond,
Here's a quick example:
https://player.vimeo.com/video/145576537
Hey Brian - thanks for whipping that up together quickly!
I was so close before you sent that. I had the wrong variable name input and didnt' match it with what was in the code.
Thanks so much again!
Ray
I've been thinking of a simple way of inserting an expiry date into a standalone presentation (I mean one that is not within an LMS).
Example application - if I made a sample presentation and emailed it out, but I wanted to prevent it being viewed past a certain date.
I haven't come across any way yet, so I wonder if this method could be used to do that - by coding in the 'currentdevelopment date' into the javascript that Brian demonstrated....and then if I only wanted the presentation to be viewable for the next 2 months say, I would make a sum that took the 'user system date' minus 60, and if it was positive, jump to a branch that ended the presentation (as it was being viewed more than 2 months in the future).
Does that sort of make sense? Sorry, if I've missed a really simple way of achieving the same thing - just haven't found a way yet!
Cheers
This solution was great! When I tested it on IE 7, I got the output I expected.
However when I tested in Chrome and in Firefox the variable did not display, just a blank space.
Any ideas on the difference?
thanks-
Claudine
I am also having trouble with getting the script to work on IE8. I copied it exactly as in the example. Is there something I should change?
Hi All,
It doesn't work in all browsers. Perhaps it can with a tweak, but by default it doesn't work in Firefox (version 18) and DOES work in IE (version 9)
Working with Javascript also required some Flash security settings when running it on a local machine:
Global Security Settings panel
Berno, That did the trick. I had seen this before with "Print Results". I couldn't test it on my local computer before posting to our website, but once posted it worked. Thank you so much! Now I can test these things before I post.
Steve
Thanks Brian!
This should work great - I have to simulate a button that inserts todays date and this should do it. As I only want the date to appear when they press the buton i will just do a trigger to change the state to make it 'appear'.
Hi Brian,
I have tried many different things trying to get your variables working. I thought maybe it was my project causing a glitch, so I started a new project with a blank slide just like your tutorial (I have watched now about 30 times). But still no success. I can not figure out what I am doing wrong. Any help? Attached is the blank slide for your reference.
if I use the story_html5.html file as opposed to story.html then it works in all my browsers.
Hi Daniel and Welcome to E-Learning Heroes! So, are you good-to-go now, or did you still have a question. Just want to be sure that I have not missed anything. Thanks so much and have a great day!
Could anyone (or Brian) please tell me how to modify Brian's javascript so that I can get the current date minus x number of days. The script needs to recognize that the result has to be an actual date; not a negative number. So, if it's only 12/3/2013, subtracting 5 days shows 12/28/2013, NOT 12/-2/2013.
Here's the script which works to get today's date:
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);
I spend all this afternoon but I can't get the date. It is blank........
Please help me what is wrong??
Assuming that you are using the code snippet in the post above, make sure that you have a Storyline variable 'SystemDate' defined.
Also, just to add to what Michael is saying, most browsers will not run the JavaScript when you run the course locally on your PC. To test properly you have to upload the course to a web server or LMS.
Hi Jenny,
To back up what Nancy said, if you aren't ready to upload to your LMS or web server yet, you could look at testing it out at tempshare.articulate.com or using Amazon S3 as a web server. The directions here will walk you through how to set up an Amazon S3 account.
Fantastic solution, many thanks Brian.
Posting a further query here in case anybody has already figured this out. :)
I wish to display my date format as 01/Jan/2018.
I have figured out the "Jan" bit (using https://stackoverflow.com/questions/27480262/get-current-date-in-dd-mon-yyy-format-in-javascript-jquery)
but I am struggling a little to display the day as "01" and not just "1".
Solutions?
My current javascript command reads:
var m_names = new Array("Jan", "Feb", "Mar",
"Apr", "May", "Jun", "Jul", "Aug", "Sep",
"Oct", "Nov", "Dec");
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
var dateString=day + "/" + m_names[month] + "/" + year;
var player = GetPlayer();
player.SetVar("systemdate",dateString)
function getDayFormatted (iDay){
var day = iDay;
return day < 10 ? '0' + day : day;
}
Thanks Berno for sharing here! This discussion is a bit older, but I'm certain the ideas may help others who come across it!
I am working on an elearning and need to display a date based on the next available day. The scenario I am working with is a lawyer is only available on Tuesdays for a meeting. If the user taking the module on Thursday 07/15/2021 the date I need displayed in the module would be 07/20/2021.
Is this possible using Javacoding? If so, could someone help me with how the code would need to be written?
thank you!