Question

In "appendix H Prompt API for IBM cognos BI" there is a example on how to use a method call addValues. However everyAttempt i have tried has left me with 0 results. Here is the code that ive been trying to use that does not produce any errors.

   window.onload = function()
{
var oCR = cognos.Report.getReport("_THIS_");
       function setPromptValue(promptName, useValue, displayValue ) {
    var oP = oCR.prompt.getControlByName( promptName );

var oValue =( {"use": useValue, "display": displayValue});
oP.addValues( [oValue]);
}
setPromptValue ( 'L', 'ca', 'Canada');
}

Im basically passing the name of my control wich is "L" and saying to use the 'ca' but display Canada. it does not work at all. Has anyone been able to do this? I've been at it for hours now and have had any luck, any help would be greatly appreciated. Thanks all Miguel

Was it helpful?

Solution

I suggest using either the 'Static Choices' or the 'Use Value'/'Display Value' feature in Cognos to solve this problem.

On your prompt page, where you have defined your drop down list, there are three properties.

With Static Choices, you can define a list of choices specific to this report that are always available in the drop down. This can be used instead of or in addition to using a query to fill the contents of your Dropdown tool.

Static Choices in Cognos 8.4.1

Here you can set Use to 'ca' and Display to 'Canada' and the ca/Canada choice will always be available.

Now ca = 'Canada' is a fairly reusable setting, so the best solution is probably to have a table that defines Country Codes and their Names (lets refer to it as COUNTRY_CODES). Once COUNTRY_CODES is setup in framework manager, you can create a query that pulls the country codes you want the user to select from, then in the Drop Down properties under the 'Query' property, specify the query you created.

Next you go to the 'Use Value' property and select the country code field (where 'ca' is). In the 'Display Value' property select the Country Name field (where 'Canada' is).

OTHER TIPS

You didn't say what type of control is your prompt control. If the control is a Value prompt you have to make sure the "use" value is valid, otherwise it will be ignored. When setting a value the "display" value is not necessary. You don't need the window.load, just executing the function works. I tried the following example and it worked.

(function() {
var oCR = cognos.Report.getReport("_THIS_");
function setPromptValue(promptName, useValue, displayValue ) {
    var oP = oCR.prompt.getControlByName( promptName );
    var oValue =( {"use": useValue});
    oP.addValues( [oValue]);
}
setPromptValue ( 'L', 'ca');})()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top