Is it possible to drill down multiple levels via code mode?

Dillon Hoefener shared this question 3 years ago
Answered

I have a use case for auto-drilling a report for a drill hierarchy that may contain up to 10 drill levels. The request is for a user to be able to essentially bookmark a drill level; this particular case is a region hierarchy, where a regional manager may save a bookmark for drill level 5 and if that bookmark is applied, the dashboard should launch and automatically drill into that level.

I see the report API has a drillUpLevels function that would work if I wanted the same effect drilling up, but I don't see the capability to do the same thing drilling down.

Below shows what I want to accomplish, where I would launch the dashboard, look at the applied filter values (for filters named "Region 0" --> "Region 9", and the drill hierarchy corresponding to those values, top level being Region 0 down to Region 9), and drill to the lowest level of saved filter values. But, the drill function in the report API will not drill to a lower level in the hierarchy than the current level. Is there a way I can achieve this that I'm not seeing?


let appliedFilterVals = [],
    regionDrillVal,
    regionFilterId;
filters.forEach((filter) => {
    if (filter.name.includes('Region') && filter.valueOne !== undefined) {
        appliedFilterVals.push(Object.assign({
            name: filter.name,
            id: filter.id,
            uuid: filter.uuid,
            value: filter.valueOne
        }));    
    }
});

appliedFilterVals.sort((a,b) => (a.name > b.name) ? 1 : -1);
if (appliedFilterVals.length > 0) {
    regionDrillVal = appliedFilterVals[appliedFilterVals.length - 1].value;
    regionFilterName = appliedFilterVals[appliedFilterVals.length - 1].name;
    // drill to the lowest level of the drill hierarchy with a saved filter value
    report.drill(regionFilterName,regionDrillVal)
}

Replies (3)

photo
1

I came across the solution to my problem. I did not realize the field ID persists throughout the drill hierarchy, so the drill API function can be called to drill multiple levels deep based on the breadcrumb values.

For anyone else who may be interested in setting up this functionality, I used text parameters to pass the drill state and drill field ID to in order to save the values as a bookmark and reference them on dashboard launch.

// Declare variables or insert code here
let canvas = this.apis.canvas,
    filters = this.apis.filters,
    drillValFilter = filters.getFilter('Drill State'),
    drillFieldFilter = filters.getFilter('Drill State Fields');
    drillValues = drillValFilter.valueOne,
    drillField = drillFieldFilter.valueOne,
    appliedDrillState = [],
    //region selector report used as drill hierarchy to filter other reports on
    regionElement = canvas.select('All_Region Selector');

regionElement.onReportLoad.then(() => {
    let selectorAPI = regionElement.reportAPI;
    
    //auto-drill on bookmarked drill values
    if (drillValues !== 'none' && drillValues !== '') {
        appliedDrillValues = drillValues.split(',')
        appliedDrillValues.forEach(val => selectorAPI.drill(drillField, val));
    }

    //capture drill state as param values
    selectorAPI.addListener('drilldown', (event) => {
        let drillState = event.eventData.drillState,
            drillStateArr = drillState.map(el => el.value);
            
        drillValFilter.setValueOne(drillStateArr.toString(), true);
        drillFieldFilter.setValueOne(drillState[drillState.length-1].fieldId);
    });
});

photo
1

Hey Dillion,

I was in the middle of trying to figure this out myself when I saw your solution!

I believe this is likely the cleanest way we can do this, however I've gone ahead and reached out to my team to see if there are any other paths that can be taken and will let you know what I find out.

Best,

Jared

photo
1

Hey Dillon,

I haven't seen a better implementation of this multi-level drill down.

As this is the case I will go ahead and mark this as answered. Thanks for sharing your solution!

Best,

Jared

Leave a Comment
 
Attach a file