/************************************************** This script is used to synchronize the selections of a pair of Year (numeric) filters *************************************************/ /** The second filter will be automatically set to one year prior to the first filter. E.g. if the first filter is set to 2025, the second filter will automatically be updated to 2024 ***/ /************************************************** The script also replicates the disabled state from the first filter to the second filter **********************************************/ //Specify the names of the filters, starting from the first filter. This is the only part of this script that requires your input. var filterNames = ['Fiscal Year', 'Fiscal Year to Compare'] //Every time a filter is changed, this code is executed dashboard.on('filterschanged',function(d) { //Find the first filter by name var filter1FilterObject = dashboard.filters.$$items.find((item) => { if (item.jaql && item.jaql.title.indexOf(filterNames[0]) !== -1) { return true; } }); //Get the JAQL filter selection of the first filter var filter1FilterObjectJAQL = filter1FilterObject.jaql; //Get the JAQL filter disabled state of the first filter var filter1FilterObjectDisabled = filter1FilterObject.disabled; //Find the second filter by name var filter2FilterObject = dashboard.filters.$$items.find((item) => { if (item.jaql && item.jaql.title.indexOf(filterNames[1]) !== -1) { return true; } }); if(typeof filter2FilterObject != 'undefined') { filter2FilterObject.jaql.filter.members[0] = filter1FilterObjectJAQL.filter.members[0] - 1; filter2FilterObject.disabled = filter1FilterObjectDisabled; } //Refresh the dashboard dashboard.refresh(); });