官术网_书友最值得收藏!

Automatic selection and submission of values

A business report has numerous prompts on the prompt page. Often, users want to run a report for the latest month in the database, 'Camping Equipment' product and 'E-mail' as a order method.

They want a facility to either manually select vales for these prompts; or alternatively, run the report for the above selections on single button click.

In this recipe, we will add a custom button on prompt page that will allow users to quickly run the report for frequently used selections.

Getting ready

Create a list report with product line, order method, and sales quantity as columns.

Create optional filters on product line, order method, and Shipment Month that is, Month Key (Shipment Date).

Create a prompt page with three value prompts for these filters.

How to do it...

  1. We will start by wrapping the prompts within spans, so that they can be captured easily in JavaScript. Add one HTML tag before and one after each prompt to define Spans. Define the spans as PL, OM, and SM for Product Line, Order Method, and Shipment Month respectively. This is similar to the wrapping we did in most of the prior recipes.
  2. Add one more HTML item on the prompt page after all the prompts, and define it as follows:
    <script>
    function defaultSelect()
    {
    var a = document.getElementById("PL");
    var PL = a.getElementsByTagName("select");
    for( var i = PL.length-1; i >= 0; i-- ) /* Captures Product Line prompt */
    {
    var PLBox = PL[i];
    }
    
    a = document.getElementById("OM");
    var OM = a.getElementsByTagName("select");
    for( var i = OM.length-1; i >= 0; i-- ) /* Captures Order Method prompt */
    {
    var OMBox = OM[i];
    }
    
    a = document.getElementById("SM");
    var SM = a.getElementsByTagName("select");
    for( var i = SM.length-1; i >= 0; i-- ) /* Captures Shipment Month prompt */
    {
    var SMBox = SM[i];
    }
    PLBox.selectedIndex = 2;
    OMBox.selectedIndex = 2;
    SMBox.selectedIndex = 2;
    canSubmitPrompt();
    promptButtonFinish();
    }
    </script>
    <button type="button" onclick="defaultSelect()" class="bt" style="font-size:8pt">Run for Defaults</button>

    Now your prompt will look similar to the following screenshot in Report Studio:

    How to do it...
  3. Run the report to test it. You should see a button that you did not see in Report Studio. When you click on the button, it will automatically select the prompt values and run the report.
    How to do it...

How it works...

In this recipe, we are mixing two techniques learnt from previous recipes. In the Dynamic default selection recipe, we learnt how to capture a value prompt and change its selection.

So, we are using the same technique here but instead of calling on Page Load, we are calling the routine when users click on the button.

Then we are also using a function promptButtonFinish() that we used in the 'Textbox validation' recipe to submit the prompt.

The custom button is defined using <button> tag and as it is our own object, we can easily make it call our JavaScript function for the onclick event.

As mentioned in the 'Dynamic default selection' recipe, practically you will not hard-code the selectedIndex in your script. Instead, you should traverse through all prompt selection options and choose one based on the value. For example, look for 'Camping Equipment' so that its order in the list won't matter.

Please refer to one such example on the IBM website at this URL: http://www-01.ibm.com/support/docview.wss?uid=swg21343424

There's more...

This technique is very useful in real-life scenarios. You can define multiple buttons for different frequently used selections. It saves time for users and makes the reports convenient to use, especially when there are more than five prompts.

主站蜘蛛池模板: 清水河县| 汶上县| 屏南县| 阿拉善右旗| 赤水市| 台州市| 边坝县| 从江县| 长宁县| 兴隆县| 石楼县| 神木县| 京山县| 句容市| 壶关县| 南投市| 石城县| 镇雄县| 台南市| 新民市| 三原县| 孟连| 渑池县| 濉溪县| 荣昌县| 确山县| 格尔木市| 灵台县| 新蔡县| 轮台县| 抚顺县| 舞钢市| 昌吉市| 自治县| 安宁市| 肥西县| 水富县| 焦作市| 梅河口市| 北京市| 大洼县|