title: IBM Cognos Report Studio: Value prompt default selection from prompt "default text" parameter
body: <p>I have a value prompt that references the parameter 'Year_Parameter', and a list with one column (a Data Item Expression) that references the same parameter as the value prompt in this way:</p>
  
  <pre><code>#prompt('Year_Parameter')#
  </code></pre>
  
  <p>The value prompt has some static choices: 2011, 2012 and 2013.
  Hence, when I run my report, and enter 2012 in the prompt page that pops up before the report page is shown, 2012 has automatically been selected in the value prompt from its list of choices when the report page is shown.</p>
  
  <p>Furthermore, if I put 2012 in the list of default selections, no prompt page is shown, and 2012 has also now automatically been selected for the value prompt when the report is shown.</p>
  
  <p>However, if I remove 2012 from the list of default selections, and change my Data Item Expression to either of these expressions:</p>
  
  <pre><code>#prompt('Year_Parameter', 'token', '2012')#
  #prompt('Year_Parameter', 'token', 2012)#
  #prompt('Year_Parameter', 'string', 2012)#
  #prompt('Year_Parameter', 'string', '2012')#
  </code></pre>
  
  <p>... no prompt page pops up as when 2012 were specified as the default selection, but no value is automatically selected for the value prompt. The value prompt shows its default Header Text: The parameter name - Year_Parameter".</p>
  
  <p>Remember the prompt function definition:</p>
  
  <blockquote>
    <p>prompt ( prompt_name , datatype , defaultText , text , queryItem ,
    trailing_text )</p>
  </blockquote>
  
  <p>Anyone know why this is happening, and more importantly a solution for how to be able to select the default selection for the value prompt, by specifying it in the Data Item Expression?</p>
  
  <p>Is it because the prompt() macro only attempts to fetch the value of the parameter 'Year_Parameter', but in itself does not fill the parameter with a value? The parameter must be given by some value prompt (on a prompt page or embedded in a report page).</p>
  
  <p>Hence, the defaultText argument to the prompt function, will NEVER fill the parameter itself, but be returned by this specific prompt function in cases where the parameter has no (valid) value?</p>
  
  <p>Thank you very much in advance for any input!</p>
  
  <p>Edit: Found this explanation on how to dynamically assign a default value to parameters.</p>
  
  <p><a href="http://cognosknowhow.blogspot.no/2013/04/how-to-dynamically-set-up-default-value.html" rel="noreferrer">http://cognosknowhow.blogspot.no/2013/04/how-to-dynamically-set-up-default-value.html</a></p>
  
  <p><strong>Final:</strong> I ended up using the following Javascript to dynamically select value prompt and update the report:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  // This function updates the report dynamically for the current year
  // The function is wrapped inside a setTimeout call in order to avoid an error caused by too frequent requests
  setTimeout(function updatePrompt() {
      var oCR = cognos.Report.getReport("_THIS_");
      var yearPrompt = oCR.prompt.getControlByName("YearPrompt");
      var selectedValue = yearPrompt.getValues()[0];
  
      if (typeof selectedValue === "undefined") {
          currentYear = new Date().getFullYear();
          yearPrompt.setValues([{'use':currentYear}]);
          // Update report
          oCR.sendRequest(cognos.Report.Action.FINISH);
      }
  }, 50);
  &lt;/script&gt;
  </code></pre>