cancel
Showing results for 
Search instead for 
Did you mean: 

Update Dashboard Date filter from selected Date to Last 365 days

nazeer475
7 - Data Storage
7 - Data Storage

Hi Team,

We have requirement where we need to update dashboard date filter dynamically from selected date to Last 365 days from the date selected.

We have a working code for windows, we are looking the same for Linux, attaching the windows code below, please help in fixing.

var TABLE = "tablename";
var COLUMN = "columnname";
var COUNT = 365;
var max = null;

dashboard.on("widgetbeforequery", function(d, a) {
var item = a.query.metadata.find(function(i) { return i.panel === "scope" && $$get(i, "jaql.table") === TABLE && $$get(i, "jaql.column") === COLUMN });

var title = $$get(item, "jaql.title");
//debugger;
if (title == "Date") {
var selopt, unselopt, selrng;
try { selopt = $$get(item,"jaql.filter.members"); } catch (e) { }
try { unselopt = $$get(item,"jaql.filter.filter.exclude.members"); } catch (e) { }
try { selrng = item.jaql.filter.to; } catch(e) { }

var fItems=[], dItems=[];
if(selopt) {
for(i=0;i<selopt.length;i++) {
fItems.push(moment(selopt[i]).toISOString().slice(0,10));
}
}
if(unselopt) {
for(i=0;i<unselopt.length;i++) {
dItems.push(moment(unselopt[i]).toISOString().slice(0,10));
}
}

if(dItems.length>0) {
for(i=0; i<dItems.length; i++) {
var fl = fItems.length;
for(j=0;j<fI;j++) {
if(fItem[j]==dItem[i]) {
fItem.splice(j,1);
--fl;
}
}
}
}

if(fItems.length>0) {
fItems = fItems.sort(function(a,b) {return moment(a) - moment(b);});
max = fItems[fItems.length-1];
} else if(selrng) {
max = selrng;
}

} else {
// replacing members with last/next

delete item.jaql.filter.from;
delete item.jaql.filter.members;

item.jaql.filter.last = {
offset: 0,
count: 365,
anchor: max
};

}

});

Thanks

Naz

0 REPLIES 0