18 February 2015

COGNOS: Setting current month as default value-prompt without Javascript

Occasionally developers resort to Javascript has the way to set the current month as default value-prompt. This result can also be achieved using a single Data Item with some MDX code in the Static Choice Property.
The picture bellow helps with the visualization of the end result. We have to override the default value-prompt item with the value of the current month.

To achieve the result just follow the steps:

  1. Add a Value Prompt control and connect to a data item to return the months;

  2. In Properties, set Static Choice property as: Use: MDX code to return the current month Display: Some description that will be visible to the end user;

  3. Values used in this example: Use: linkMember(item(members([ECS Cube].[Tempo].[Current Month].[Mês]);0);[ECS Cube].[Tempo].[Tempo].[Mês]) Display: Actual.  

Tip1: linkMember function is compatible just with Cognos Cubes;
Tip2: The MDX code has to return a member from the same hierarchy added in the data item.

  • To ensure that the Static Choice value be selected by default, set Default Selections Property with the same MDX code used in Static Choice.

.

.

.

.

    Bruno Paulino
      Consultant
Blog