Forum Discussion

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

Widget to display time

Hi,

We have a requirement where we have to display the local timezone of the country that is being selected from the dashboard filter. The dashboard filter on country has values like Italy, France, Netherlands, UK, US etc. When the user selects "Italy" in the filter, i want the widget to display the value of Italy's local time, irrespective of the timezone of the user. The same widget should display France's local time when the user selects "France" from the filter. Do we have an out of box/ built-in widget to display time (like a clock widget).

6 Replies

Replies have been turned off for this discussion
  • Harry's avatar
    Harry
    Cloud Apps

    Hello R1 ,

    One solution is to add a Text widget to dashboard and add below dashboard script. In the script, update the variable 'filterName' with name of Country filter, 'textWidgetID' with ID of Text widget and 'countryTimeZoneMapping' with area-time zone name mapping

    
    dashboard.on('filterschanged', function(se, ev){
    	displayTime(se)
    })
    
    dashboard.on('widgetready', function(se, ev){
    	displayTime(se)
    })
    
    function displayTime(se){
    	let filterName = 'Country' //update the name of country filter
    	let textWidgetID = '6380c6426bc7f50039bf366b' //update widget-id of text widget
    	
    	
    	let selectedCountry = ''
    	
    	//update area-timezone mapping
    	let countryTimeZoneMapping = {
    		'Brazil':'America/Sao_Paul',
    		'France':'Europe/Paris',
    		'Canada':'America/New_York',
    		'India':'Asia/Calcutta'
    	
    	}
    	
    	let filterObject = se.filters.$$items.find(el=>el.jaql.title == filterName)
    	
    	if(filterObject && filterObject.jaql.filter && filterObject.jaql.filter.members)
    		selectedCountry = filterObject.jaql.filter.members[0]
    	
    	let dateString = new Date().toLocaleString('en-US', { timeZone: countryTimeZoneMapping[selectedCountry]});
    	$(`widget[widgetid="${textWidgetID}"] richtexteditor .wd`).text(dateString)
    
    }

     

     

    Please let me know if have any questions

    Always here to help,
    Harry from QBeeQ

    QBeeQ - Gold Implementation and Development Partner
    www.qbeeq.pl

     

     

    • R1's avatar
      R1
      Data Storage

      Hi Harry,

      Thank you so much. That helps. Could you kindly let me know how do i find the widget ID of the text widget in question?

      Regards,

      R

    • R1's avatar
      R1
      Data Storage

      Hi Harry,

      Thank you so much. That helps. Could you kindly let me know how do i find the widget ID of the text widget in question? I tried finding out the widget ID of the text widget from the Console by giving "prism.activeDashboard.widgets.toArray()" and got the ID. But, the time doesn't get displayed while selecting the filter. Attaching the screenshot of the dashboard too.