Audit Hierarchies on All Workviews

Joined
Jul 24, 2020
Messages
4
Likes
1
Points
3
#1
Hi Modlr,

We need to complete an audit of all our work views to see which hierarchy the work view is pointing too.

Is there any efficient way / report I can run to get this information quickly rather then manually going through each work view one by one.

Regards,

Paul
 

Ben Hill

Administrator
Staff member
Administrator
Joined
Mar 19, 2018
Messages
37
Likes
29
Points
18
#2
Hi Paul,

I've had a chat with Amin on this and we have added a new process function workview.definitionGet which will return the JSON format definition of a workview. This can then be parsed to list the involved hierarchies. I'll add here and in the support ticket an example process shortly.

Thanks,
Ben
 
Joined
Nov 21, 2021
Messages
1
Likes
0
Points
1
#3
I noticed this problem was solved offline years ago, however I'd just like to include this solution that I've used elsewhere for future reference.

I've written a quick MODLR process which takes a dimension and a hierarchy as prompts and creates a csv file in the model's file system (under Exports/) containing all the workviews that utilize that hierarchy.

Before using this process you'll need to modify the line let workview_base_url = "https://go.modlr.co/workview/your-instance-name-here/your-model-id-here/" and replace the indicated parts of the URL with the relevant info from your model.

JavaScript:
/**
 * 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.');
}