Double the Power, Double the Insights: Oracle APEX and MicroStrategy for Data Pros!
Oracle Apex und Oracle Analytics together look here:
A Guide to Embedding Oracle Analytics into Oracle APEX | by Mike Durran | Oracle Developers | Medium
But we have Customers with Microstrategy an OLD - BI Tool Dog with Bitcoins!
Step 1: Define the Login Process to Get a Token from MicroStrategy
Before embedding MicroStrategy dashboards, an authentication process needs to be established to retrieve a token. This token facilitates secure, authorized access to MicroStrategy resources.
On the LOGIN button in APEX, we execute the following JavaScript code:
async function runAuthenticationProcess() {
console.log('Mstr Authentication');
await manageAuthentication(:P9999_username, :P9999_password);
}
runAuthenticationProcess();
Step 2: Store MicroStrategy-Related Files in APEX APP_FILES
Storing JavaScript files within APP_FILES in Oracle APEX allows easier integration and loading of MicroStrategy content.
mstr_integration.js
- Content Overview
This file, based on the MicroStrategy SDK, handles the embedding of the MicroStrategy dossier within the APEX environment:
(function(global) {
// Helper function to get the value of a specific cookie
function getCookieValue(name) {
let match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
if (match) {
return match[2];
}
return null;
}
async function embeddingMstr() {
let cookieToken = getCookieValue('x-mstr-authtoken');
let authToken = cookieToken;
if (!authToken) {
console.log("No valid token found, creating a new one.");
authToken = await createAuthToken();
}
if (authToken) {
// Library+Dossieridentifier ist here used
let url = mstr_baseServerUrl + "/" + mstr_libraryName + "/app/LONGSTRING/LONGANOTHERSTRING";
let config = {
url: url,
placeholder: document.getElementById("dossier"),
containerHeight: "1200px",
containerWidth: "100%",
customAuthenticationType: microstrategy.dossier.CustomAuthenticationType.AUTH_TOKEN,
enableCustomAuthentication: true,
enableResponsive: false,
navigationBar: { enabled: false },
filterFeature: { enabled: false },
token: authToken
};
/* Apply a Filter On Dashboard Creation Start */
config.filters = [
{
key: "LONGFILTERSTRINGIDENTIFIER", // Replace with the key of the filter that is being edited
selections: [
{
name: apexArtikelnr, // Replace with value of selection
},
],
},
];
try {
let dossier = await window.microstrategy.dossier.create(config);
console.log("Dossier embedded successfully.");
} catch (error) {
console.error("Failed to embed dossier with error:", error);
}
} else {
console.log("Failed to authenticate, please check credentials or token.");
}
}
// Expose the function to the global context
global.embeddingMstr = embeddingMstr;
}(window));
// Call the function to embed the dossier
//embeddingMstr();
Step 3: Configure Additional JavaScript for MicroStrategy Server Variables
In a second JavaScript file, define the server-specific variables and authentication functions required for MicroStrategy:
let mstr_baseServerUrl = "https://analytics.wwww.at:8443";
let mstr_libraryName = "MicroStrategyLibrary";
let apexArtikelnr = "12345";
// Helper function to set a cookie
function setCookie(name, value, days) {
let expires = "";
if (days) {
let date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + (value || "") + expires + "; path=/";
}
// Authentication Management with dynamic credentials
async function manageAuthentication(username, password) {
async function getAuthToken() {
const options = {
method: "GET",
credentials: "include",
mode: "cors",
headers: { "content-type": "application/json" },
};
return fetch(`${mstr_baseServerUrl}/${mstr_libraryName}/api/auth/token`, options)
.then(response => {
if (response.ok) {
return response.headers.get("x-mstr-authtoken");
} else {
response.json().then(json => console.log(json));
}
})
.catch(error => {
console.error("Failed to retrieve authToken:", error);
throw error;
});
}
async function createAuthToken() {
const options = {
method: "POST",
credentials: "include",
mode: "cors",
headers: { "content-type": "application/json" },
body: JSON.stringify({ loginMode: 1, username, password }), // loginmode=16 = LDAP
};
return fetch(`${mstr_baseServerUrl}/${mstr_libraryName}/api/auth/login`, options)
.then(response => {
if (response.ok) {
console.log("Login session created successfully.");
let authToken = response.headers.get("x-mstr-authtoken");
setCookie("x-mstr-authtoken", authToken, 30); // Set the cookie for 30 days
return authToken;
} else {
response.json().then(json => console.log(json));
}
})
.catch(error => {
console.error("Failed Standard Login:", error);
throw error;
});
}
}
Step 4: Load JavaScript Files in the Target APEX Page
On the target page in APEX, load these JavaScript files under Page Attributes to ensure they’re ready for use when the page loads.
Step 5: Create a Region for Dossier Embedding
Within the target APEX page, create a Static Content region with the static ID "dossier"
. This serves as the placeholder for the MicroStrategy dossier.
Step 6: Use a Dynamic Action to Load the Library
Using a Dynamic Action (DA) in APEX, trigger the embeddingMstr()
function on page load or another specified event, which will load the dossier into the "dossier"
region.
An DA helps to load the library:
ACTION:
and soooo the Library is loaded in Oracle APEX and shows the dossier..
Resources:
https://microstrategy.github.io/playground/login
MicroStrategy Embedding SDK Playground Tutorial - Attribute Selector Filter (youtube.com)
microstrategy.github.io/embedding-sdk-samples/feature_showcase/6_Filters.html