Cognos Prompt API Usage for Interactive Reports
Requirements:
Prompt page and report are on same page for dynamic refresh
User wants date to be selected for latest month available in Database
Solution steps:
http://www-01.ibm.com/support/docview.wss?uid=swg21639520
Issues Faced:
Solution:
Add line of code in script using below reference:
http://cogblogger.com/2014/10/javascript-running-code-only-once/
Prompt page and report are on same page for dynamic refresh
User wants date to be selected for latest month available in Database
- Calculated maximum month as latest month for report
- Sorted Data item in descending order and applied sorting on prompt ( auto submit = yes)
- Use Prompt API for RS to select latest month referring below link
Page was getting reset to default selection even we select different month.
Solution:
Add line of code in script using below reference:
http://cogblogger.com/2014/10/javascript-running-code-only-once/
if (typeof firstRun == 'undefined'){
// 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("promptMonth");
// 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);
var firstRun = false;
}
var zxcv = {};
// Get the required prompt.
var oCR = cognos.Report.getReport("_THIS_");
var oP = oCR.prompt.getControlByName("promptMonth");
// 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);
var firstRun = false;
}
Issue Faced:
Initial run of report is not filtering out data based on prompt parameter and showing aggregated value.
Solution:
Use of prompt macro to make default parameter as latest month and made filter "Required" instead of Optional.
[Month Year] = #prompt('p_Month_Year', 'string', '[Max Month Year]')#