Forum Discussion

R1's avatar
R1
Data Storage
11-29-2022

Dynamic date display in text widget

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?

 

1 Reply

Replies have been turned off for this discussion
  • R1's avatar
    R1
    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?

    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")
    }
    });