COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: niahanth on 23 Jan 2016 04:56:07 PM

Title: Javascript for date prompt
Post by: niahanth on 23 Jan 2016 04:56:07 PM
Hi,
I have two date prompts Begin Date and End Date. Can anyone help me with the javascript code when while running the report if we enter begin date > end date it should display a message like "The dates selected ate invalid"

Thanks
Title: Re: Javascript for date prompt
Post by: bdbits on 26 Jan 2016 05:40:53 PM
You want this on the prompt page? Do you have any javascript skills?

Or on the report itself, you could use conditional rendering. Have two objects on the report, one could be a text item with your message and the other your report data container (list, crosstab, etc.). The date check will render the text item if true, and the report data container if false.
Title: Re: Javascript for date prompt
Post by: afzaki7 on 28 Jan 2016 09:01:20 AM

hey my friend
here is the scenario

(http://i64.tinypic.com/ip3yxh.jpg)

1-add table contain 1 column and 3 rows
2-in the first two rows add two Dateprompt  name the first DP1 and the second DP2
3 in the third row add 2 HTML element
4- in the first HTML element add this script
Quote
<script>
    function myfunction() {
        var fW = (typeof getFormWarpRequest == "function" ? getFormWarpRequest() : document.forms["formWarpRequest"]);
        if (!fW || fW == undefined) {
            fW = (formWarpRequest_THIS_ ? formWarpRequest_THIS_ : formWarpRequest_NS_);
        }
        var Date1 = new Date(fW.txtDateDP1.value);
        var Date2 = new Date(fW.txtDateDP2.value);

        var day1 = Date1.getDay();
        var month1 = Date1.getMonth(); //months from 1-12
        var year1 = Date1.getFullYear();

        var day2 = Date2.getDay();
        var month2 = Date2.getMonth();
        var year2 = Date2.getFullYear();

        if (year2 > year1) {
            alert('no way')
        } else if (year2 == year1) {
            if (month2 > month1) {
                alert('no way');
            } else if (month2 == month1) {
                if (day2 > day1) {
                    alert('no way');
                } else {
                    alert('ok')
                }

            } else {
                alert('ok');
            }
        } else {
            alert('ok')
        }
    }
</script>

5- in the second HTML element add this script


Quote<button type="button" onclick='myfunction();' > Click Me!</button>

now you can replace the alert message of whatever you want
no way = failed ----> alert the user of what you want
ok = pass -----> call finish function ex:promptButtonFinish();

Thanks