Some basic techniques for JavaScript Programming of Cognos Prompts 总结

以下是IBM的文档,最新的已经被更新,这是旧的。

大概看了一下,我总结一下。

Some basic techniques for JavaScript Programming of Cognos Prompts

 

4 Retrieving prompts

To retrieve a prompt, first get the object containing the whole form.

  var form = getFormWarpRequest(); 

Note 1:  the use of getFormWarpRequest() is not fragment-safe.  

Note 2: in 8.2 the code is: 

var form = document.forms["formWarpRequest"];

4.1 Standard prompts

The standard prompts objects can be accessed as properties of the formWarpRequest object, with the following naming conventions:

• Text Edit Box   _textEditBox<prompt name>
• List Box  _oLstChoices<prompt name>
• Drop Down List _oLstChoices<prompt name>
• Radio Button Group  _oLstChoices<prompt name>
• Check Box Group  _oLstChoices<prompt name>
• Date Edit Box   txtDate<prompt name>

Example: to get the listBox prompt which has been named XYX, the code is:

var form = getFormWarpRequest();
var listB  = form._oLstChoicesXYZ;

4.2 Other prompts

All other prompt objects can be accessed by adding a named span tag <span> around the prompt object and accessing the span tag via the getElementById() function and the prompt object items using the getElementsByTagName() function.

See details in the reference 7.1 below.

 

 

5 Common Actions on Prompts
5.1 Modifying the prompts before the prompt page is displayed

To modify a prompt, create a HTML item, and write a script to retrieve the prompt and set a value for the prompt.
In the following examples, the prompt has the name XYZ.
5.1.1 Set a value for a text box

Create a Text Box Prompt and a HTML item containing:

  var form = getFormWarpRequest();
      var textB  = form._textEditBoxXYZ;
      textB.value="First value";
canSubmitPrompt();

See also Technotes 1370539 and 1339524.

5.1.2 Select an item in a multiselect List Box

Create a Value Prompt, and change the “Multi-Select” property to Yes. This example selects the third value in the list.

var form = getFormWarpRequest();
var listB  = form._oLstChoicesXYZ;       listB.options[2].selected=true;
 canSubmitPrompt();

See also Technotes 1371328 and 1342809.
5.1.3 Remove the first 2 lines from a Drop Down List prompt

Create a Value Prompt. By default, the “Select UI” attribute is DropDownList. The first line contains the parameter name, the second line contains dashes and the actual data starts only on the third line. Some customers want to remove the first two lines:
       var form = getFormWarpRequest();
       var dropDownL  = form._oLstChoicesXYZ;
       dropDownL.remove(1);
       dropDownL.remove(0);
       dropDownL.removeAttribute("hasLabel");  // needed only in Cognos 8.3/8.4
   canSubmitPrompt();

See also Technote 1342899.
5.1.4 Enable the “Finish” button

In a page containing some required prompts, the Finish button is enabled only when the user has selected values for all the required prompts.
The current section shows examples when the prompts are initialized by script.  If all the required prompts are satisfied, then the “Finish” button may be set to enabled, by calling the function:

canSubmitPrompt()

Example: a prompt page contains two prompts:

1. a Text Box Prompt, named ABC, which should be initialized with the string “Hello”;
2. a Value Prompt of the type ListBox, named DEF, where the first item should be selected. After that, the “Finish” button should be set to Enabled.

       var form = getFormWarpRequest();
       var textB  = form._textEditBoxABC;
       textB.value = "Hello";
       var listB  = form._oLstChoicesDEF;
       listB.options[0].selected=true;
       canSubmitPrompt();

Note 1: all the required prompts must be satisfied before calling canSubmitPrompt(). Otherwise the following error message is displayed:

“One or more of the required values is missing. Required values are needed to produce the report”.

Note 2: canSubmitPrompt() has been introduced in Cognos 8.3. It checks all the prompts in the page. In Cognos 8.2 the same operation was done by the function checkData(), applied for each prompt. The function checkData() applies to specific variables for each prompt. Such a variable has a name as in the following list, followed by the prompt name:
• checkBoxGroup
• clockDisplay
• intervalControl
• listBox
• pickerControl
• radioGroup
• search
• selectDate
• selectDateTime
• selectInterval
• selectTime
• textBox
• timePicker
The same example, now written in Cognos 8.2 will be:

var form = document.forms["formWarpRequest"];
var textB  = form._textEditBoxABC;
textB.value="Hello";
var listB  = form._oLstChoicesDEF;
listB.options[0].selected=true;
textBoxABC.checkdata();
listBoxDEF.checkdata();

Note 3: checkData() is still available in Cognos 8.3/8.4.
 
5.2 Running scripts after the user clicks the Finish button

By default, pressing the Finish button will execute the report with the given prompts. In order to execute additional operations after the user presses the Finish button, but before the report runs, replace the Finish button with a customized one, as follows:
• Define a JavaScript function to do the expected actions
• Define a new button to launch the function above
• Remove the original Finish button

Example: a prompt page contains a list and a text box. When Finish is pressed, the text box is filled with the selected option. The prompt page should have:
• the list prompt
• the text prompt
• a HTML item next to the Finish button, containing:

<input type="BUTTON" class="clsPromptButton" onClick="fillTextBox()" value="Finish">

• a HTML item containing the requested function, followed by the promptButtonFinish() call, which will perform the Finish button action.

<script>
function fillTextBox() {
 var form = getFormWarpRequest();
 var list = form._oLstChoicesABC;
 var textBox = form._textEditBoxXYZ;

 for (i = 0; i < list.length; i++) {
  if (list.options[i].selected) {
   textBox.value = list.options[i].value;
   break;

  }
 }
 promptButtonFinish();
}
</script>
 

6 Debugging JavaScript

6.1 Detecting JavaScript errors in Internet Explorer (IE)

In the bottom left corner of the IE window, usually there is the IE blue icon and the text “Done”. Sometimes the icon is the yellow alert sign and the text says “Error on page”. That means an error has been detected in JavaScript. By double clicking the icon, an error dialog appears, with the line and text of the error.
6.2 Using Firebug debugger in Firefox

Firefox has a very good HTML/JavaScript debugger, called Firebug. It can be downloaded as a Firefox add-on.
Once installed, it will appear like a small bug icon in the bottom toolbar. Clicking this icon will open/close a bottom section of the window, where the Firebug data resides.
In this Firebug window some useful operations are:
• On the “Script” tab, the script from the current page is displayed. Most of the script is created Cognos. The user created script can be found close to the end of the script tab. For debugging, a breakpoint can be added by clicking at the left of a line in the script. A red circle appears as a bookmark. When the script is stopped at a bookmark, usual debugging is available as inspecting variables or step over/into the code.
• On the “HTML” tab, the content of the HTML document is presented as a tree. The user can expand the tree and hover the mouse over HTML tags; the corresponding part in the web page above will appear in light blue.
• If the user presses the “Inspect” button, then hover over the web page, the corresponding area in the HTML document is highlighted in light blue. This is very useful when the user wants to find the HTML for a web area.

 

以上说的是:

Javascript可以在Cognos执行效果:

(1)

The standard prompts objects can be accessed as properties of the formWarpRequest object, with the following naming conventions:

  • Text Edit Box           _textEditBox<prompt name>
  • List Box         _oLstChoices<prompt name>
  • Drop Down List    _oLstChoices<prompt name>
  • Radio Button Group  _oLstChoices<prompt name>
  • Check Box Group    _oLstChoices<prompt name>
  • Date Edit Box            txtDate<prompt name>

Example: to get the listBox prompt which has been named XYX, the code is:

var form = getFormWarpRequest();

var listB  = form._oLstChoicesXYZ;

STEPS:

  1) 在报表的查询页面,增加一些控件,例如增加一个ComboBox控件,名称为:XYZ,

  2)增加一个HTML控件,然后放入js脚本

<script language="javascript">
function delete_listbox_line_NO_USED()
{
var form = getFormWarpRequest();  
// delete line and var1 from listbox
var listsubject  = form._oLstChoicesListSubject; //Listsubject is the name of ListBox Control 1
 listsubject.remove(0); 
 listsubject.remove(0); 
 listsubject.removeAttribute("hasLabel");  
// listsubject.options[0].text = "请选择科目";
// listsubject.options[1].selected=true;
canSubmitPrompt();
}
setTimeout("delete_listbox_line()", 10);//OK
</script>

3)执行的结果是:将原来ComboBox里面的非选项2个被删除,并且修改为选择第一个,这样用户就不用再选择,加快了操作。


 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值