cancel
Showing results for 
Search instead for 
Did you mean: 
intapiuser
Community Team Member
Community Team Member
Based on a filter date, the dashboard script looks up the max date in the filter that is not greater than today and defaults to that date. The only addition, would be to create a date range instead of defaulting to a single value. The script also prints out all the filter dimensions to the browser console to be customized on, so we suggest checking out the console once you apply the script.
var defaultFilterConfig = {

    dim1: "[DIM_DATE.DATE (Calendar)]"

};

 

dashboard.on('initialized', function(d, args) {

                //print out all dimensions

                for(var i=0; i<args.dashboard.filters.$$items.length; i++) {

                                if(args.dashboard.filters.$$items[i].levels != null) { //this is for dependent filters

                                                for(var j=0; j<args.dashboard.filters.$$items[i].levels.length; j++) {

                                                                console.log(args.dashboard.filters.$$items[i].levels[j].dim);

                                                }

                                }

                                else { //normal filters

                                                console.log(args.dashboard.filters.$$items[i].jaql.dim);

                                }

                }

               

                //query the filter dimension to retrieve all members sorted descending

                var dimJaql = '{"dim": "' + defaultFilterConfig.dim1 + '", "sort": "desc"}';

                var query = '{"datasource": ' + JSON.stringify(args.dashboard.datasource) + ', "metadata": [' + dimJaql + ']}';

                var url = '/api/elasticubes/' + args.dashboard.datasource.title + '/jaql';

                $.ajax({

                                async:false,

                                method: 'POST',

                                url: url,

                                data: query,

                                success: function(result) {

                                                //find the date that is most up to date based on today

                                                for(var x=0; x<result.values.length; x++) {

                                                                if(result.values[x][0].data.substring(0,10) <= (new Date()).toISOString().substring(0,10)) {

                                                                                break;

                                                                }

                                                }

                                               

                                                for(var i=0; i<args.dashboard.filters.$$items.length; i++) {

                                                                if(args.dashboard.filters.$$items[i].levels != null) { //this is for dependent filters

                                                                                for(var j=0; j<args.dashboard.filters.$$items[i].levels.length; j++) {

                                                                                                if(defaultFilterConfig.dim1 === args.dashboard.filters.$$items[i].levels[j].dim) {

                                                                                                                args.dashboard.filters.$$items[i].levels[j].filter = {

                                                                                                                                explicit: true,

                                                                                                                                members:[result.values[x][0].data],

                                                                                                                                multiSelection: false,

                                                                                                                                userMultiSelect: false

                                                                                                                };

                                                                                                }

                                                                                }

                                                                }

                                                                else if(defaultFilterConfig.dim1 === args.dashboard.filters.$$items[i].jaql.dim) { //this is for normal filters

                                                                                args.dashboard.filters.$$items[i].jaql.filter = {

                                                                                                explicit: true,

                                                                                                members:[result.values[x][0].data],

                                                                                                multiSelection: false,

                                                                                                userMultiSelect: false

                                                                                };

                                                                }

                                                }

                                },

                                contentType: "application/json; charset=utf-8",

                                dataType: "json"

                });

});

 

 

Rate this article:
Version history
Last update:
‎03-02-2023 09:21 AM
Updated by:
Contributors