Get date range from a Calendar Range Filter

I am not very familiar with scripting so if someone can help, I would truly appreciated it. I need to get the date range from a Cash Calendar Range Filter, update the start and end dates to lag 1 month, then set the new date range on the Revenue Calendar Range Filter. The script would run on Parameter Value Changed action.


Here is the script I currently have. When I update the Cash To date, the Revenue calendar range filter did not update as expected.

currentView = this.baseViewService.currentView;

dateParam = currentView.control.getViewParameterByName(“viewParameter 1”);
from = dateParam.parameterValue.lowerBoundaryValue.memberTime;
to = dateParam.parameterValue.upperBoundaryValue.memberTime;

dateParam2 = currentView.control.getViewParameterByName(“viewParameter 2”);
dateParam2.parameterValue.lowerBoundaryValue = from.addMonths(-1);
dateParam2.parameterValue.upperBoundaryValue = to.addMonths(-1);


In this case you’re connected to a hierarchy, not just date/time. The difference is a hierarchy groups members so that you’re able to see dates at different levels, such as months, day and years (depending on what your Time Dimension is setup as). Unfortunately your script won’t work like that because you’re taking the memberTime property, which is DateTime, and then assigning it to lowerBoundaryValue which is supposed to be a member value object. DateTime objects have no concept of ‘level’.

So you need to set those properties to a member value like in this example here.

The question though is: what member values should you use? For this there are two answers. One is that you could not use a member value at all, and instead use a token. For example there is a ‘Current Month’ token which could have an offset of -1, or just use the ‘Previous Month’ token instead. Using this way is fairly straight forward, and you can follow this example on how to do it. Getting the ID of the token to use can be a bit more work and there is an API call to assist in getting all of them.

The second answer is to find the corresponding member by date/time. One way to do this is to use the getPreviousMember and getNextMember calls on the hierarchyService. If the member you have on your parameter value is at the same level, such as the month, then these calls will return the next or previous member at the same level. The other way is to just query directly for a member that matches the specified date/time at the specified level, such as:

var getMemberDef = this.getService("HierarchyService").getMember(hierarchyId, {
                                "hierarchyUniqueName": dateParam.parameterValue.hierarchyUniqueName,
                                "levelUniqueName": dateParam.parameterValue.levelUniqueName,
                                "memberDateTime": from.addMonths(-1)
getMemberDef.done(function (memberValue) {
  if (memberValue) {

You’d have to do the same thing for the ‘to’ value. Since these are async calls you may also want to mark e.isAsync as true and resolve e.deferred when both are done, if you’re doing this inside of an action.

1 Like