Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IBM Cognos Report Studio: Value prompt default selection from prompt "default text" parameter

I have a value prompt that references the parameter 'Year_Parameter', and a list with one column (a Data Item Expression) that references the same parameter as the value prompt in this way:

#prompt('Year_Parameter')#

The value prompt has some static choices: 2011, 2012 and 2013. Hence, when I run my report, and enter 2012 in the prompt page that pops up before the report page is shown, 2012 has automatically been selected in the value prompt from its list of choices when the report page is shown.

Furthermore, if I put 2012 in the list of default selections, no prompt page is shown, and 2012 has also now automatically been selected for the value prompt when the report is shown.

However, if I remove 2012 from the list of default selections, and change my Data Item Expression to either of these expressions:

#prompt('Year_Parameter', 'token', '2012')#
#prompt('Year_Parameter', 'token', 2012)#
#prompt('Year_Parameter', 'string', 2012)#
#prompt('Year_Parameter', 'string', '2012')#

... no prompt page pops up as when 2012 were specified as the default selection, but no value is automatically selected for the value prompt. The value prompt shows its default Header Text: The parameter name - Year_Parameter".

Remember the prompt function definition:

prompt ( prompt_name , datatype , defaultText , text , queryItem , trailing_text )

Anyone know why this is happening, and more importantly a solution for how to be able to select the default selection for the value prompt, by specifying it in the Data Item Expression?

Is it because the prompt() macro only attempts to fetch the value of the parameter 'Year_Parameter', but in itself does not fill the parameter with a value? The parameter must be given by some value prompt (on a prompt page or embedded in a report page).

Hence, the defaultText argument to the prompt function, will NEVER fill the parameter itself, but be returned by this specific prompt function in cases where the parameter has no (valid) value?

Thank you very much in advance for any input!

Edit: Found this explanation on how to dynamically assign a default value to parameters.

http://cognosknowhow.blogspot.no/2013/04/how-to-dynamically-set-up-default-value.html

Final: I ended up using the following Javascript to dynamically select value prompt and update the report:

<script type="text/javascript">
// This function updates the report dynamically for the current year
// The function is wrapped inside a setTimeout call in order to avoid an error caused by too frequent requests
setTimeout(function updatePrompt() {
    var oCR = cognos.Report.getReport("_THIS_");
    var yearPrompt = oCR.prompt.getControlByName("YearPrompt");
    var selectedValue = yearPrompt.getValues()[0];

    if (typeof selectedValue === "undefined") {
        currentYear = new Date().getFullYear();
        yearPrompt.setValues([{'use':currentYear}]);
        // Update report
        oCR.sendRequest(cognos.Report.Action.FINISH);
    }
}, 50);
</script>
like image 644
Skovly Avatar asked Oct 02 '22 10:10

Skovly


1 Answers

Exactly, as Skovly is saying, the prompt macro can't fill in the value to the parameter. From the link provided I'd choose javascipt (first option) but keep in mind IBM changes the syntax from version to version.

(I don't know yet how to post comments on answers, otherwise I'd attach it to the previous one to stregthen the opinion that you can't do what you want with prompt macro).

like image 53
Jan Svatos Avatar answered Oct 12 '22 00:10

Jan Svatos