I had a request that always have data shown. I had the default date set to a current time period (like current week or month) but because Finance does not finalize right away that would give me No Data.
So I wrote a little script to go back one period if there was no data.
This was working great until a user tried to go back further than what the data set had.
It got in a none stopping loop and was back in the 1400’s when i got to it.
The Tip here is not only how to go back but how to control it from going for ever and not being able to change the date because the script is firing so fast you can set it to current period.
// Get the parent view.
var parentView = this.parentView;
// Get the view parameters.
var viewParameters = parentView.control.viewParameters;
// Using the library, get the view parameter based on it’s name
var viewParameter = this.parentView.control.getViewParameterByName(“dateViewParameter”);
//Go back one time period on offset but limit to 5 time periods, use what ever number is best for you
if (viewParameter.parameterValue.token.offset > -5)
{
viewParameter.parameterValue.token.offset = viewParameter.parameterValue.token.offset -1;
viewParameter.invalidateParameterValueLastModifiedTime();
viewParameter.refreshAllAdapters();
}
Additional:
This was not an issue when I had it not remembering what the last filter you had (“Personalizations”), they could just reload and it would use default. I also have it so that do not see full screen, they just see the dashboard. they cannot get to their profile to clear personalizations.
But even if your users can get to this or reload to fix it, this is better it lets them right away gain control of the filter.