Forum Discussion

amelia's avatar
06-23-2022
Solved

Show Last Updated Date on Dashboard

Hi! I'm creating a dashboard and want to show when the data source for the dashboard was last refreshed at the top of the dashboard, since the users will want this. Is there any widget I can add or s...
  • harikm007's avatar
    harikm007
    06-30-2022

    amelia 

    Create a text box and add below script to it. (Update elasticube name in the script.)

     

    function runHTTP() {
    	
    	datasource = [
    					{
    						"elasticube": "elasticube name",
    						"server": "localhost"
    					}
    				]
      // Use $internalHttp service if exists
      const $internalHttp = prism.$injector.has("base.factories.internalHttp") ?
      prism.$injector.get("base.factories.internalHttp") : null;
      // Ajax configurations
      const ajaxConfig = {
        url: "/api/v1/elasticubes/getElasticubes",
        method: "POST",
        data: JSON.stringify(datasource),
        contentType: "application/json",
        dataType: "json",
        async: false
      };
      // Use $internalHttp service for v8.0.1+
      // else use default ajax request
      const httpPromise = $internalHttp ? $internalHttp(ajaxConfig, true) : $.ajax(ajaxConfig);
    
      // Return response
      return httpPromise.responseJSON;
    };
    
    
    widget.on('domready', function(se, ev) {
      elasticubedetails = runHTTP();
      ev.widget.style.content.html = '<font size=\"5\">' + moment(elasticubedetails[0].lastBuildTime).format('MMMM Do YYYY, h:mm:ss a') + '</font>' //change this to update style and text
    })

    Thanks Ophir_Buchman for the post 'how to run HTTP request from sisense'

    -Hari