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

Cognos 10.2 Prompt API

Started by svb, 14 Aug 2014 11:35:36 AM

Previous topic - Next topic

svb

Hello,

can some one please guide me through COGNOS 10.2 API?

I'm using the below script to dynamically pre-select the first value in the prompt but I'm on version 10.2 so want to convert this script using prompt API.


<script type="text/javascript">

var fW = (typeof getFormWarpRequest == "function" ? getFormWarpRequest() : document.forms["formWarpRequest"]);
if ( !fW || fW == undefined) {
  fW = ( formWarpRequest_THIS_ ? formWarpRequest_THIS_ : formWarpRequest_NS_ );
}
var yr1=fW._oLstChoicesDem_Year1;
if ( yr1 && yr1.options.length > 2 && yr1.options.selectedIndex == 0 ) {
  yr1.options.selectedIndex = 2;
}
</script>

I tried this: (from IBM Support docs)

<script>
// Attach functions to an arbitrarily named object to mimic a namespace to ensure the name uniqueness
var zxcv = {};

// Get the required prompt.
var oCR = cognos.Report.getReport("_THIS_");
var oP = oCR.prompt.getControlByName("Year");

// Get the values and isolate the first value.
var allValues = oP.getValues(true);
var firstValue = allValues[0];

// Set the prompt selection to the first value.
oValues = [firstValue];
oP.setValues(oValues);

</script>

this is not pre-selecting the first value.prompt is on the report itself and set to auto submit.
Kindly help!

CognosPaul

What do you mean by pre-select? The Prompt API will only take affect after the report has run, meaning that if this appears on the report page then the first run of the report will not be filtered by this prompt. There are several ways of ensuring that the report is pre-filtered by a specific value, but I need to better understand the issue.

Also, it's good practice to use a uniquely defined namespace, but the var zxcv isn't actually doing anything here.

It would be better to define some functions that so you can do this, without polluting the global namespace with variables. See here: http://stackoverflow.com/questions/8862665/what-does-it-mean-global-namespace-would-be-polluted

Try the following:


<script>
var paulScripts ={}
  , oCR = cognos.Report.getReport("_THIS_");

paulScripts.getControl = function(promptName) {
  return oCR.prompt.getControlByName(promptName);
};

paulScripts.selectFirstValue = function(promptName){
  var prm = paulScripts.getControl(promptName);
  prm.setValues(prm.getValues(true)[0]);
}

</script>

You can then call the functions with

<script>
paulScripts.selectFirstValue('Year');
</script>

It's worth mentioning that if you just leave the HTML item as is, it will always select the first value after the page loads - even if the user selects another year. You can set the HTML item to report expression with:

case when paramValue('Year') is null then '<script>
paulScripts.selectFirstValue(''Year'');
</script>'
end

This way the JS will only kick in when the parameter is null.


svb

Hello Paul,

First of all, thank you so much for taking time to review my problem and providing me with a detailed answer. You are THE BEST! ( I do follow your blog regularly  ;) )
By pre-select I meant default selection. I want the prompt to default to the current year(fiscal 2014-2015) which would be the first value in the prompt.

I tried your script but it still doesn't default to the first value:

This is what I'm doing:
I have a dimensional model

Slicer:

[Cube].[Fiscal Year].[Fiscal Year].[Fiscal Year]->?Year?
drop a value prompt: use existing parameter - 'Year' and then select the level from year hierarchy

prompt set to autosubmit. prompt name: Year

html item in the header

<script>
var paulScripts ={}
  , oCR = cognos.Report.getReport("_THIS_");

paulScripts.getControl = function(promptName) {
  return oCR.prompt.getControlByName(promptName);
};

paulScripts.selectFirstValue = function(promptName){
  var prm = paulScripts.getControl(promptName);
  prm.setValues(prm.getValues(true)[0]);
}

</script

html item after the prompt

case when paramValue('Year') is null then '<script>
paulScripts.selectFirstValue(''Year'');
</script>'
end

since it is a required prompt it pops up. it is not defaulting to the first value in the prompt

what m i doing wrong here?

I also tried a [Current Year] data item with the expression: closingPeriod([Cube].[Fiscal Year].[Fiscal Year].[Fiscal Year]). Prompt default selection: [Current Year]
This does not update the prompt selection to 2014-2015 (obviously), but renders the chart with current year numbers.

Also, I cannot have a Current year static choice in the prompt.



karthik.kadambi

Hi Paul,

I couldn't get your script working for me as well. I sent you a PM about this.

<script>
var paulScripts ={};
var oCR = cognos.Report.getReport("_THIS_");

paulScripts.getControl = function(promptProject) {
  return oCR.prompt.getControlByName("promptProject");
};

paulScripts.selectFirstValue = function(promptProject){
  var prm = paulScripts.getControl("promptProject");
  prm.setValues(prm.getValues(true)[0]);
}

</script>