------需求:
第一次打开报表就自动输入默认值。
------解决方案:
在report studio内增加以下javascript.
<script type="text/javascript">
var theSpan = document.getElementById("A1");
var theSelect = theSpan.getElementsByTagName("select");
theSelect[0].options[2].selected=true; //这行可以使默认值成为下拉列表虚线下的第一个值
theSelect[0].options[0].text = '<可以在这里给下拉列表取名字>';
canSubmitPrompt();
</script>
[@more@]
------详细方案英文原版:
Title:
Javascript: Changing first line and set default selection in value prompt for 8.3
Document#:
1038662.3
Updated:
Dec 01, 2008
Applies To:
Cognos 8 BI Report Studio 8.3
SRs:
1
Collection:
KB
--------------------------------------------------------------------------------
Note: This technique uses JavaScript against underlying report objects and methods in a IBM Cognos 8 BI report. For this reason, there is no guarantee that reports created using this technique will migrate or upgrade successfully to future versions without requiring modifications. Any such modifications are the responsibility of the report designer.
Description:
The following is a sample Javascript that allows for the first item in a value prompt to be selected and the descriptive text of the value prompt to be renamed in Cognos 8.3.
Environment:
C8.3 Report Studio
Root Cause:
Prompt objects in Cognos 8.3 are now dynamically named. This is why methods such as:
document.formWarpRequest._oLstChoicesprompt1[0].text = 'Select a Order Method...';
document.formWarpRequest._oLstChoicesprompt1.options[0].selected = true;
may no longer work because of the way in referencing the objects. The solution below is one way to access the objects.
Solution:
Surround the value prompt with HTML items in Report Studio, then add a third HTML item at the bottom of the prompt page with new script
Steps:
1. Add an HTML item to the left and right of the value prompt in the Report Studio
2. For the first HTML item (left) add '<span id = "A1">'
3. For the second HTML item (right) add '</span>'
4. Add an HTML item at the bottom of the prompt page next to "Run" button
5. Add the following script for the third HTML item:
<script type="text/javascript">
var theSpan = document.getElementById("A1");
var theSelect = theSpan.getElementsByTagName("select");
theSelect[0].options[2].selected=true; //This will make default value in prompt to be the first item after line, change the value '2' for other item
theSelect[0].options[0].text = '<PUT WHATEVER TEXT FOR VALUE PROMPT TITLE HERE>';
canSubmitPrompt();
</script>
6. The value "A1" can be anything you like. Run the Report. This works well when using prompt page.
7. Add the following script if you don't want to use a prompt page, and want to use auto-submit in the value prompt within the same page as the list/crosstab. In this case the third HTML item is put after the second HTML item that contained the close span. The first two HTML item will still need to be in the left and right of the value prompt object. The script looks like:
<script type="text/javascript">
function init()
{
var theSpan = document.getElementById("A1");
var theSelect = theSpan.getElementsByTagName("select");
theSelect[0].options[2].selected=true; //This will make default value in prompt to be the first item after line, change the value '2' for other item
theSelect[0].options[0].text = '<PUT WHATEVER TEXT FOR VALUE PROMPT TITLE HERE>';
promptButtonFinish();
}
</script>
<body onLoad=init()>
Related documents:
The following knowledge base articles describe additional methods of modifying the formWarpRequest to access the same objects in Cognos 8.3.
1013968 - Javascript: Changing the First Line of a Value Prompt or DropDownList prompt.
1036117 - JavaScript: Sample to automatically select first item in value prompt
Upgrading Javascript Applications to IBM Cognos 8.3/8.4
http://support.cognos.com/en/support/diagnostics/pdf/upgrading_javascript_applications.pdf
Keywords:
8.3 Script Value Prompt Title Default Selection Java