Hey liamcameron ,
the Dynamic Elasicube require the Datasource info in the script to be Dynamic Variable.
datasource = [
{
"elasticube": "elasticube name",
"server": "localhost"
}
]
This sample script demonstrates the following:
- Wrapping the HTTP request inside a dashboard script using the 'initialized' event.
- Dynamically creating the 'elasticube' variable based on the dashboard's datasource.
- Triggering the HTTP request once the dashboard is fully initialized.
- Tested by manually switching the data source (Has not been tested with Dynamic Elasticube plugin).
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;
}
Please test and confirm if it works
Best Regards