Forum Discussion
liamcameron
10-15-2024Cloud Apps
hey Assaf!
Thank you for the reply, i've tried the second script in a text widget, doesn't seem to work, is there something else i need to input? i.e you define the data sources, do i need to outline my cubes beforethe script?
AssafHanina
10-20-2024Sisense Employee
Hey liamcameron ,
The copy was missing the necessary code to update the text.
in addition, instead of Using Text option, the Last Build time can be used in Blox Widget.
please review the updated script, Using Text, and update if that's works.
let datasource;
dashboard.on('initialized', function(dashboard) {
// Extract the Elasticube title from the dashboard's datasource
datasource = [
{
"elasticube": dashboard.datasource.title, // Replace with the actual datasource title
"server": "localhost"
}
];
// Run the HTTP request once the datasource is ready
runHTTP();
});
function runHTTP() {
// Ensure datasource is available
if (!datasource) {
console.error("Datasource not available");
return;
}
// 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+ or default ajax request
const httpPromise = $internalHttp ? $internalHttp(ajaxConfig, true) : $.ajax(ajaxConfig);
// Return the response
return httpPromise.responseJSON;
}
// display last build in Text
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
})
Best Regards