Topic
  • 6 replies
  • Latest Post - ‏2013-01-31T14:25:14Z by DanielWagemann
HariPrashath
HariPrashath
28 Posts

Pinned topic Prob in Selecting Current Year in Value Prompt (Dropdown)

‏2013-01-30T12:23:50Z |
Hi,

I have writen a java script to pick the current Year in the Dropdown by default, but it throws the following error message.
I have set my the dropdown Object name as "XYZ" in "Miscellaneous Name".

Error Message:

Message: 'ff._oLstChoicesXYZ' is null or not an object
Line: 128
Char: 1
Code: 0

Code:

<script type="text/javascript">
var ff= getFormWarpRequest();
var listDateFrom =ff._oLstChoicesXYZ
function yyear()
{
var Stryear =new Date().getFullYear();
return Stryear;
}
ff._oLstChoicesXYZ.setValue(yyear() );
</script>
Thanks

HP
Updated on 2013-01-31T14:25:14Z at 2013-01-31T14:25:14Z by DanielWagemann
  • DanielWagemann
    DanielWagemann
    411 Posts

    Re: Prob in Selecting Current Year in Value Prompt (Dropdown)

    ‏2013-01-30T18:16:23Z  
    Are you sure that setValue method is available for your value prompt? If not, you may need to traverse the prompt values with a for loop to see if the value is equal to your current year.
  • DanielWagemann
    DanielWagemann
    411 Posts

    Re: Prob in Selecting Current Year in Value Prompt (Dropdown)

    ‏2013-01-30T19:06:42Z  
    Are you sure that setValue method is available for your value prompt? If not, you may need to traverse the prompt values with a for loop to see if the value is equal to your current year.
    The following works for me in 10.1.1 using Internet Explorer. I had to -7 from the current date so it would jive with the sample data.

    <script type="text/javascript">
    function init()
    { 
      var fW = (typeof getFormWarpRequest == "function" ? getFormWarpRequest() : document.forms["formWarpRequest"]);
      var Stryear =(new Date().getFullYear()-7);
      currentValue=fW._oLstChoicesMyPrompt;
      var i=0;
     
      if (fW)
        {
          for(i=2;i<currentValue.length;i++)
            {
              if(currentValue.options[i].value==Stryear)
              {
                currentValue.options[i].selected = true;
               }
            }
    canSubmitPrompt();
    }
    }
    init();
    </script>
    
    Updated on 2014-03-25T07:43:27Z at 2014-03-25T07:43:27Z by iron-man
  • HariPrashath
    HariPrashath
    28 Posts

    Re: Prob in Selecting Current Year in Value Prompt (Dropdown)

    ‏2013-01-31T09:53:33Z  
    The following works for me in 10.1.1 using Internet Explorer. I had to -7 from the current date so it would jive with the sample data.

    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr"><script type="text/javascript"> function init() { var fW = (typeof getFormWarpRequest == "function" ? getFormWarpRequest() : document.forms["formWarpRequest"]); var Stryear =(new Date().getFullYear()-7); currentValue=fW._oLstChoicesMyPrompt; var i=0; if (fW) { for(i=2;i<currentValue.length;i++) { if(currentValue.options[i].value==Stryear) { currentValue.options[i].selected = true; } } canSubmitPrompt(); } } init(); </script> </pre>
    Daniel,

    Thanks for the Inputs, the code picks the correct value in the Dropdown but it again display the Prompt Page with Text item, where I have to enter the Year ID manually.

    Thanks

    HP
  • DanielWagemann
    DanielWagemann
    411 Posts

    Re: Prob in Selecting Current Year in Value Prompt (Dropdown)

    ‏2013-01-31T13:11:20Z  
    Daniel,

    Thanks for the Inputs, the code picks the correct value in the Dropdown but it again display the Prompt Page with Text item, where I have to enter the Year ID manually.

    Thanks

    HP
    I am sorry but I don't understand what it is you are after. The original post was against a JavaScript throwing an error when attempting to pick a current year value out of a value prompt.

    Your latest post mentions being prompted to type something in a text field. Unless you can clarify what it is you are looking for, I will not be able to help you further.
  • HariPrashath
    HariPrashath
    28 Posts

    Re: Prob in Selecting Current Year in Value Prompt (Dropdown)

    ‏2013-01-31T13:34:27Z  
    I am sorry but I don't understand what it is you are after. The original post was against a JavaScript throwing an error when attempting to pick a current year value out of a value prompt.

    Your latest post mentions being prompted to type something in a text field. Unless you can clarify what it is you are looking for, I will not be able to help you further.
    Daniel,

    Let me make it simple, my requirement is to run a report with default Prompt value - Current Year and Current Month.
    To achieve this
    • I created two value prompt (Dropdown) for Year and Month
    • I have put the Java script to pick the Current Year and Current Month as default values.

    but even after this, when I run the report it prompts to enter the Year and Month.

    Kindly guide me on this

    Thanks

    HP
  • DanielWagemann
    DanielWagemann
    411 Posts

    Re: Prob in Selecting Current Year in Value Prompt (Dropdown)

    ‏2013-01-31T14:25:14Z  
    Daniel,

    Let me make it simple, my requirement is to run a report with default Prompt value - Current Year and Current Month.
    To achieve this
    • I created two value prompt (Dropdown) for Year and Month
    • I have put the Java script to pick the Current Year and Current Month as default values.

    but even after this, when I run the report it prompts to enter the Year and Month.

    Kindly guide me on this

    Thanks

    HP
    I wish you would have said that in the first place. All you are looking for is your report to run the first time with the month and year defaulted to the current date.

    You will need to make the prompt object and filter optional.
    Then you can change your filter to use a prompt macro with a default value. Something like:

    #prompt('YearPromptName','integer','[MyCurrentYearCalc]')#=[Year]
    


    where the MyCurrentYearCalc would be a query calculation with a definition of:
    extract('year','current_date')
    


    You don't need any JavaScript for this.
    Updated on 2014-03-25T07:43:23Z at 2014-03-25T07:43:23Z by iron-man