I have 3 prompts. 1st Prompt contains the values A & B. On selecting A the remaining 2 prompts should get hidden and upon selecting B the 2 prompts should show. All the 3 prompts are mandatory. Can anyone help me achieve this scenario?
1 Answers
I'm going to assume that you already know how to conditionally hide and unhide elements and that you just want to know how to refresh a page without submitting it.
There are three solutions to your problem:
- Add a reprompt button
- Use JavaScript to detect when the radio button has changed state and reprompt the page
- Use a workaround that uses a hidden value prompt
Method 1 - Reprompt Button
This is done by simply adding a prompt button to the report and setting the 'Type' property to 'Reprompt'. I don't recommend you use this method as requiring the user to click a reprompt button each time they change a prompt value is bad user experience.
Method 2 - JavaScript API
This method uses the Cognos-supported JavaScript API to reprompt the page whenever a value prompt changes value. Note that the API is only available in version 10.2 and later.
- Name your value prompt. This is specified in the prompts 'Name' property. For the purposes of this tutorial, I'm going to use the name 'valuePrompt'.
- Add an 'HTML Item' to the report.
- Open the HTML item and paste in the following code:
<script>
var report = cognos.Report.getReport('_THIS_');
var valuePrompt = report.prompt.getControlByName('valuePrompt');
var currentValues = (valuePrompt.getValues().length == 0) ? [{'use':''}] : valuePrompt.getValues();
valuePrompt.setValidator(validateValuePrompt);
function validateValuePrompt(values) {
if (values && values.length > 0) {
if (values[0].use != currentValues[0].use) {
currentValues = values;
report.sendRequest(cognos.Report.Action.REPROMPT);
}
} else {
currentValues = [{'use':''}];
}
return true;
}
</script>
The code is optimized so that the reprompt action only happens when the prompt is changed to a new value. This prevents multiple reprompts whenever the system checks the prompts for validity, which can happen quite often.
Method 3 - Hidden Dependent Prompt
This technique uses a hidden value prompt to trick Cognos into reprompting the page on every value prompt change by tying the prompt to a dummy value prompt using the cascading prompt functionality.
- Add a new value prompt
- Set the new prompt's 'Required' property to 'No'
- Set the 'Cascade Source' property for the new prompt to be the parameter of the previously existing value prompt
- Hide the new prompt
- Set the 'Auto-Sumbit' property of your original value prompt to 'Yes'.
Whenever you change the value prompt, the page will reprompt in order to refresh the hidden prompt.

- 2,005
- 1
- 13
- 15
-
-
Hi Johnsonium, The second solution was the one which I was expecting. That worked fantastically! Thanks for the support! – Saraban Jun 15 '16 at 07:30
-