- IBM Cognos 8 Report Studio Cookbook
- Abhishek Sanghani
- 666字
- 2021-08-06 17:15:50
Dynamic default value for prompt
There is a report which allows users to select a shipment month. The Shipment Month dimension has values up to current month. However, users frequently select prior month. They want the prompt to have prior month selected by default.
Getting ready
Take any report that filters on Shipment Month Key. Add a value prompt to the Shipment Month Key on the prompt page.
How to do it...
- Select the value prompt and define its sorting such that the Shipment Month Keys are populated in descending order.
- Now, as we know the dimension is always populated up to the current month and values are sorted in descending order, we will write a code that selects second value from top by default.
- For that, add an HTML Item just before the Shipment Month value prompt. Define the HTML as:
<span id = 'A1'>
- Add another HTML item just after the value prompt and define it as:
</span>
- Now add another HTML item to the prompt page footer, just after the Finish button.
- Define it as:
<script> var theSpan = document.getElementById("A1"); var a = theSpan.getElementsByTagName("select"); /* This stmt return an array of all value prompts within span */ for( var i = a.length-1; i >= 0; i-- ) /* now loop through the elements */ { var prompts = a[i]; if( prompts.id.match(/PRMT_SV_/)) { prompts.selectedIndex = 3; } /* This selects the second options from top */ canSubmitPrompt(); } </script>
- Execute the report to test it.
How it works...
The logic used here is that we first sort the months in descending order and then select the second option from top. As the values populated from the database are up to the latest month, the second value from top will be the previous month.
As mentioned at the beginning of the chapter, Report Studio prompt pages are similar to any other HTML pages with most of the controls being standard web controls. The HTML item in Report Studio is a powerful component which allows us to embed our own code within the page generated by Cognos.
When we put a JavaScript within an HTML item, it is automatically executed when the page loads.
With Cognos 8.3, the report viewer architecture has been majorly changed. With CRN 8.1 and 8.2, it was a common practice to define a NAME
or ID
for the prompt controls and use that to manipulate controls at runtime through JavaScript.
However, version 8.3 onwards, the IDs of the controls are generated randomly and are not fixed. So, it is a little difficult to get hold of a control. For this reason, we have defined a SPAN around the control that we want to manipulate.
By wrapping the control within SPAN tags, we will reduce the scope of our search in JavaScript.
As we want to capture the Value Prompt within span, we search elements with select
tag within the span A1.
If we want to perform same operation on multiple value prompts, we can put them all within same span. The GetElementsByTagName
function returns an array of elements with the specified tag.
Once a value prompt object is captured in a variable, we can set its SelectedIndex
property to set the selection to required value.
There's more...
A more suitable example of 'dynamic selection' will be iterating through the value prompt options and selecting one based on a condition.
You can use the Java functions to capture system date and accordingly work out the Prior Month. Then traverse through all the values and select an appropriate one. Similarly, you can iterate through all the prompt values and select the required entry based on value instead of hard-coding the selectedIndex
to 3.
Please refer to one such example on the IBM website at this URL: http://www-01.ibm.com/support/docview.wss?uid=swg21343424
- 現(xiàn)代企業(yè)應(yīng)用設(shè)計(jì)指南
- 自己動(dòng)手寫分布式搜索引擎
- IBM Cognos 8 Report Studio Cookbook
- Vue.js框架與Web前端開(kāi)發(fā)從入門到精通
- Photoshop CC 實(shí)戰(zhàn)入門
- Dreamweaver CC實(shí)例教程(第5版·微課版)
- SketchUp/Piranesi印象彩繪表現(xiàn)項(xiàng)目實(shí)踐
- Joomla! 1.5 Site Blueprints: LITE
- Microsoft Dynamics GP 2010 Reporting
- 抖音+剪映+Premiere短視頻制作從新手到高手(第2版)
- Power Query For Excel:讓工作化繁為簡(jiǎn)
- MATLAB在日常計(jì)算中的應(yīng)用
- 動(dòng)畫制作基礎(chǔ)(項(xiàng)目教學(xué)版)
- Illustrator CC 2018 基礎(chǔ)與實(shí)戰(zhàn)教程(全彩版)
- 攝影師的后期必修課(RAW格式篇)