I have a prompt page and a page with a list. The user selects the values from the prompt page and the report page is then generated. A usual report.
The prompt page has a multi select list box with 20 values.
What i want to do is: When the user selects up to 3 values from the list box then in the report header show the values with ParamDisplayValue('param1'), if the user select more than 3 show ") items selected" eg: "5 items selected"
You can use the Cognos JavaScript API to store the selection count in a hidden prompt for later use. Here are the steps:
<script>
var report = cognos.Report.getReport('_THIS_');
var multiPrompt = report.prompt.getControlByName('multiPrompt');
var countPrompt = report.prompt.getControlByName('countPrompt');
multiPrompt.setValidator(validateMultiPrompt);
function validateMultiPrompt(values) {
if (values && values.length > 0) {
countPrompt.addValues([{'use':values.length}]);
} else {
countPrompt.addValues([{'use':'0'}]);
}
return true;
}
</script>
On your report you can have a report expression like so:
if (ParamDisplayValue('param2') in ('1','2','3'))
then (ParamDisplayValue('param1'))
else (ParamDisplayValue('param2') + ' items selected')
This expression assumes that the multi-prompt is assigned param1 and the new hidden prompt is assigned param2.
For this to work the multi-select prompt must be required. Otherwise, when nothing is selected your item would read '0 items selected'. This can be worked around by adding a render variable to the item which only renders the item when param1 is not missing or param2 equals '0'.