COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: karthik.kadambi on 09 Aug 2015 09:19:48 PM

Title: Prompts on Report Page with JavaScript
Post by: karthik.kadambi on 09 Aug 2015 09:19:48 PM
Hi Cognoise members,

I have a set of prompt controls set up this way on a Report Page instead of a Prompt Page:

Value Prompt 1 (single select, default value) | Value Prompt 2 (single select, default value) | Value Prompt 3 (multiselect, default value picked up by JavaScript)

JavaScript Code which dynamically selects the first value:
<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("promptCountries");

// 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>


I understand that the JavaScript code will not be submitted unless I hit the "Finish" button. I would want to filter the query on the Report Page based on the first value selected when the Report is first run.

Adding this piece to the code constantly refreshes the page every sec.
oCR.sendRequest(cognos.Report.Action.FINISH);
Title: Re: Prompts on Report Page with JavaScript
Post by: bvk.cognoise on 10 Aug 2015 01:13:36 AM
Hi Karthik,

Please try below mentioned code

<script type="text/javascript">
function init()
{
var fW = (typeof getFormWarpRequest == "function" ? getFormWarpRequest() : document.forms["formWarpRequest"]);
if (fW)
fW._oLstChoicesPromptName.options[2].selected = true;
canSubmitPrompt();
}
init();
</script>


Regards
Bvk
Title: Re: Prompts on Report Page with JavaScript
Post by: karthik.kadambi on 10 Aug 2015 09:51:28 AM
Hi Bvk,

Thanks. It's doing the same as the one I posted. The JavaScript picks the element but doesn't filter the Report for that specific one, but instead runs for everything.