cognoscognos-10cognos-bicognos-8

To Prevent Auto Submit from generating the report in Cognos


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?


Solution

  • 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:

    1. Add a reprompt button
    2. Use JavaScript to detect when the radio button has changed state and reprompt the page
    3. 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.

    1. 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'.
    2. Add an 'HTML Item' to the report.
    3. 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.

    1. Add a new value prompt
    2. Set the new prompt's 'Required' property to 'No'
    3. Set the 'Cascade Source' property for the new prompt to be the parameter of the previously existing value prompt
    4. Hide the new prompt
    5. 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.