cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic date display in text widget

R1
7 - Data Storage
7 - Data Storage

Hi,

I'm trying to display the timezone of the country based on the value selected in the country dashboard filter, in a text widget. Using the below dashboard script as  kindly shared by a fellow community member, but I don't see date getting populated when the filter is selected. The text widget remains empty. Dashboard filter name, widget ID are all verified correct. What could be the reason and solution for this?

 

Screenshot 2022-11-29 at 10.50.23 AM.png

Screenshot 2022-11-29 at 10.49.06 AM.png

1 REPLY 1

R1
7 - Data Storage
7 - Data Storage

Hi,

Found a way to achieve this using Blox widget, and display the current timezone of the country based on the dashboard filter using the below script. I'm doing the conversion based on the current date and time. However, I want to use the last build date of the live model for conversion (to denote when data was last refreshed). From the documents and old community posts, i got to know how to get the last build time of an elastic cube. How do i achieve/ access the last build time of a live model in my widget script?

Screenshot 2022-12-01 at 11.09.11 AM.png

widget.on("ready", function(w, args) {

//make sure the target BloX text has an "id" attribute of "text-to-change"

var yourFilterTitle = "Market"; //insert your filter title here
//ASSUMPTION: you're using an ordinary "List"-style filter

var filterDetails = w.dashboard.filters.$$items.find(function(element){
return element.jaql.title === yourFilterTitle;
}).jaql.filter;

//$("#text-to-change").text(filterDetails.members + ": " + filterDetails.members)
if (filterDetails.members == "France" || filterDetails.members == "Italy" || filterDetails.members == "Netherlands") {
let dateString = new Date().toLocaleString('en-US', { timeZone:'Europe/Paris'});
$("#text-to-change").text(filterDetails.members + ": " + dateString + " CET")
}
else if(filterDetails.members == "United Kingdom"|| filterDetails.members == "UK"){
let dateString = new Date().toLocaleString('en-US', { timeZone:'Europe/London'});
$("#text-to-change").text(filterDetails.members + ": " + dateString + " GMT")
}
else if(filterDetails.members == "United States of America"|| filterDetails.members == "USA"|| filterDetails.members == "US"){
let dateString = new Date().toLocaleString('en-US', { timeZone:'America/Phoenix'});
$("#text-to-change").text(filterDetails.members + ": " + dateString + " MST")
}
});