/**
* Author: Jacob Wolstenholme
* Date Created: 14/02/2022
* Date Modified: 14/02/2022
*
* Parent Process: N/A
* Primary Function: Workview / Dimension insights
* Target: Workviews & Dimensions
*
*/
function pre() {
//this function is called once before the processes is executed.
//Use this to setup prompts.
script.log('process pre-execution parameters parsed.');
script.prompt("Dimension", "dim", "Period");
script.prompt("Hierarchy", "hrchy", "Month YTD");
}
function begin() {
//this function is called once at the start of the process
script.log('process execution started.');
if (!dimension.exists(dim)) {
script.abort(`Couldn't find a dimension called "${dim}"`)
return
} else if (!hierarchy.exists(dim, hrchy)) {
script.abort(`Couldn't find a hierarchy called "${hrchy}" in the "${dim}" dimension`)
return
}
let now = new Date()
let filename = "Exports/Workviews using " + hrchy + " as of " + now.toISOString().split("T")[0] + ".csv"
let csv = datasource.csv(filename);
csv.write(["Workview name", "Workview ID", "Workview URL"])
let workview_base_url = "https://go.modlr.co/workview/your-instance-name-here/your-model-id-here/"
let dim_id = dimension.getId(dim)
let workviews = JSON.parse(workview.list()[0]);
script.log(`Looking through ${workviews.length} workviews to see which use the "${dim}" dimension & "${hrchy}" hierarchy.`);
let workviews_with_hrchy = [];
for (wv of workviews) {
let dims_raw = JSON.parse(workview.definitionGet(wv.id)).dimensions;
for (id in dims_raw) {
if (id != dim_id) { continue }
for (instructions of dims_raw[id]["set"]) {
for (instruction of instructions.instructions) {
if (instruction.action == "set") {
for (thing of instruction.set) {
if (thing.hierarchy == hrchy) {
if (!workviews_with_hrchy.includes(wv.name)) {
workviews_with_hrchy.push(wv.name)
csv.write([wv.name, wv.id, workview_base_url + wv.id])
}
}
}
}
}
}
}
}
script.log(`Found ${workviews_with_hrchy.length} workviews that use the "${dim}" dimension & "${hrchy}" hierarchy.`);
csv.close()
script.log(`CSV file has been output to "${filename}"`)
script.log(workviews_with_hrchy.join(", "));
// console.log(workviews_with_hrchy);
}
function data(record) {
//this function is called once for each line of data on the second cycle
//use this to build dimensions and push data into cubes
}
function end() {
//this function is called once at the end of the process
script.log('process execution finished.');
}