No data Current Period, Auto go back to where there is data

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.

2 Likes

Hi James,

Good script. I’ve thought of things like this but i always felt that something like this would be frustrating to the user and might feel like something is wrong with the tool. I dunno. If i am a user and i right click and i drill down and it does… but then suddenly it goes back i’d feel like something was broken. I guess it depends on your user.

I’d imagine that this would be open to some debate. I’d love to hear how your users respond to this. Great idea, regardless and thanks for sharing!

The default Value for the filter is Current Week/Month. at the beginning of the month there is no data yet.
Also to note I had “Store View Personlization” off , there for each time they went to it the default showed. I had to turn that to ON and when this happened the script never started back from current when going back to the dashboard, That is when it became an issue.

When the users do not like seeing “No Data” you figure something out.