Skip to main content

Hi - we have a dynamic SKUID dashboard with a snippet refreshing the page every 5 minutes. We would like to show the current time at each refresh - something like ‘Last Updated : xxxxxxx’.

I tried by adding a template at top of the page, with the following in the HTML:
Last Updated : {{$System.Now}}

but that didn’t work. I have checked through the listed merge variables:
http://help.skuidify.com/m/11720/l/187263-global-merge-variables-functions

but don’t see System listed. Any ideas as to how to pull in the date & time ?


As an updated I tried creating a formula field with value = NOW, then pulling that into the model and adding that to the template. But as the template is set to ‘Do not run on each row’ I guess that is stopping it from working.


Looks like I answered my own question (again…)

as I already had snippet running to do the refresh, I added code to get the date/time and insert into the appropriate element on the page:


var currentTime = new Date();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var month = currentTime.getMonth() + 1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var day = currentTime.getDate();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var year = currentTime.getFullYear();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var yearstring = day + "/" + month + "/" + year;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var hours = currentTime.getHours()<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var minutes = currentTime.getMinutes()<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (minutes &lt; 10){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; minutes = "0" + minutes;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var templatetext = 'Last updated : '+hours + ':' + minutes + ' ' + yearstring;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var elements = document.getElementById('currenttime').getElementsByTagName('*');<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //console.log(elementst1].innerHTML);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elementst1].innerHTML = templatetext;

HACK ALERT * HACK ALERT * HACK ALERT

I’ve had similar issues of needing to present values up to a template (or elsewhere) via mustache.  The little trick I use is to fake it as a URL parameter, such as:


skuid.page.params.LastTime = new Date().toLocaleTimeString() 

This puts the value into in the $Param variable, which can then be accessed in a template (or elsewhere that mustache is supported) via something like:


Last updated: {{$Param.LastTime}}

I’d love it we had a more official way to pass values up to mustache, but I’ve not found it yet.

Also - for formatting the date / time - here is a short hand I have used…


new Date().toLocaleTimeString() + ' on ' + skuid.$.datepicker.formatDate(skuid.utils.userLocale.dateFormat, new Date())

which outputs something like


7:46:44 AM on 3/26/2015

So the final (hack) string to do it all is…


skuid.page.params.LastTime = new Date().toLocaleTimeString() + ' on ' + skuid.$.datepicker.formatDate(skuid.utils.userLocale.dateFormat, new Date());


- Chris


We like a good hack every once in a while.  Yours is a good one. 


I like this a lot, I just need the reverse - .toLocaleDateString works great for my date, but the .toLocaleTimeString adds seconds to the time, which makes it not work for my date/time field I’m trying to send data to through my URL

I’m trying to use .formatTime (“h:mm a”, new Date()) but it just crashes no matter what I try

e.g.
skuid.page.params.CurrentTime = new Date().formatTime (“h:mm a”, skuid.time.getSFDateTime) or 

skuid.page.params.CurrentTime = skuid.time.getSFDateTime().formatTime (“h:mm a”, new Date()) 

i just don’t know how to add the formatTime function…