cancel
Showing results for 
Search instead for 
Did you mean: 

Run an additional JAQL within your script

Ophir_Buchman
12 - Data Integration
12 - Data Integration

In various cases, you'll require additional data from your data model - Data that wasn't part of your original widget's query.

The following function allows you to query your data model as part of your javascript code (using your existing security token (without requiring repeated authentication).

USE THIS WISELY... MORE QUERIES = INCREASED LOAD TIME

Function #1 - Defines how to run an HTTP request

function runHTTP(jaql) {
// 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/datasources/" + encodeURIComponent(jaql.datasource.title) + "/jaql",
method: "POST",
data: JSON.stringify(jaql),
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;
};

Function #2 - Defines the JAQL and Runs the Request

function getCurrencySign(dashboard) {
const query = {
"datasource": "Ophir_Training",
"metadata": [
{
"jaql": {
"dim": "[Dim_Currency.Currency]",
"filter": {
"members":"USD"
}
}
},
{
"jaql": {
"dim": "[Dim_Currency.CurrencySign]"
}
}
]
};
return runHTTP(query);
}

Function #3 - Using the Function

dashboard.on('filterschanged', function(dash) {
dash.currencySign = getCurrencySign(dash).values[0][1].text;
console.log('currencySign is ' + dash.currencySign);
})
0 REPLIES 0