If you are unable to create a new account, please email support@bspsoftware.com

 

News:

MetaManager - Administrative Tools for IBM Cognos
Pricing starting at $2,100
Download Now    Learn More

Main Menu

Automatic Select Value Prompt

Started by mel4363, 29 Jul 2014 01:53:48 AM

Previous topic - Next topic

mel4363

Hi,

I have a prompt select on a financial year item and another value prompt on Month and year.. the user has an option to select as they want. What I want to achieve is when financial year is selected that the months associated with it to be automatically selected in the months value prompt. I understand there is a way to do this in javascript ? just don't know how.

The financial year and month are joined with a key in FM

I am reporting of a FM Package from a SQL server database. Currently running Cognos 10.2.1

Thank you in advance

Mel

hanfrie

Hello Mel,

As a absolute beginner in Cognos I only can suggest so much, but what about the following two ideas:
- couldn't you create a prompt that holds the concatenated values of Financial Year and month, instead of the two seperate prompts?
- create a cascading prompt in which the first prompt asks for the year and its answer is input for the second prompt, with an underlying query consisting of possible values of the combination of year and month.
No need for JS.

Regards
Hanfrie

Raghuvir

hi Mel,

even i would suggest you to use cascading prompts in your report. Try achieving your requirement by using the built in features of cognos, still if you are unable to achieve then try u sing javascripts.

Regards

mel4363

Hi Hanfrie and Rag,

Using Cascading source was my very first option, and it does work. However I the user to select financial year then all months associated with it to be selected automatically. Reason for this is I then use the months ParamCount in the report to do calculations.

Mel

CognosPaul

#4
There are three parts of setting a default value in a prompt. The the prompt expression in your query, the parameter, and the prompt object.

The prompt expression looks like:

?Month?
or
#prompt('Month','integer')#

The syntax with the question marks is a prompt alias. It's essentially shorthand for the macro. Cognos will behave differently based on how you are using the prompt. If it's in an optional filter Cognos won't require a value in the parameter, but if you're using the prompt inside a data item, case when ?Month?=1 then 1 else 2 end, then a value must be sent. A prompt macro has the advantage here in that you can give it a default value if the parameter is null:

#prompt('Month','integer',timestampMask($current_timestamp,'mm'))#

The timestampMask macro function will return the current month as MM, 07 for July for example.

The important thing to remember is that the default value in the macro does not set the parameter value. It will only set the value for that instance of the macro. That means you can have two different queries with two different behaviours in the macros. There are far more things you can do with prompt macros, but I won't get into them here.

The prompt object is the control that sets the parameter value. A default value in the macro prompt will not cascade to the prompt. Additionally, using JavaScript to set the parameter will only take affect after the page has been run. This means that the parameter is still null after the value has been set. The parameter will only get the value after a submit action, such as clicking on the finish button.

The parameter itself is usually set by the prompt object. On the first run of the report Cognos will check all existing prompts for default values, and any parameters set by the report properties.  It will then proceed to render the objects on the screen. If any query has a prompt, it will check the usage, if it's required and there is no default value it will generate a prompt. Once the page has been loaded, the JS to modify the prompt will run.

So the question here is what are your needs. If you have a dedicated prompt page, you can get away with simply using the JS solution. If you have a way of bypassing the prompt page, or if you are integrating the prompt into the report page you will also need to set the default value in the macro.

As of version 10.2, IBM released a fully supported API (meaning if it does fail, you can open a ticket, in previous versions you were always SOL).  With the API we have a nice suite of functions we can use to access and programmatically set Prompt objects. Again, this does not set the parameter until after a submit action, so you may still need to use the default parameter in the prompt macro.

Before anything, give the Prompt object a name. Like Months. The JS is very simple, it simply accesses the prompt and runs the setValues function.


<script>
var paulScripts= {};
paulScripts.getControl = function(promptName)
{
  var ocr = cognos.Report.getReport('_THIS_');
  return ocr.prompt.getControlByName(promptName);
};

paulScripts.getMonth=function(){
var d =new Date;
return  d.getMonth() +1;
}

paulScripts.getControl('Months').setValues([{'use':paulScripts.getMonth()}]);

</script>


The paulScripts object is to prevent any conflicts with existing Cognos JS functions.

You can have Cognos automatically run a script after the user selects a year by using the setValidator function. The function is ostensibly used to validate it, but it doesn't need to. I hate giving away all of the answers in one go (mostly because that means I actually need to put in some effort on the solution instead of just lecturing), so if you're still having problems tomorrow I'll give a more precise answer.