If you are unable to create a new account, please email support@bspsoftware.com

 

News:

MetaManager - Administrative Tools for IBM Cognos
Pricing starting at $2,100
Download Now    Learn More

Main Menu

Fill up a prompt using javascript

Started by hankler, 01 Dec 2016 04:30:12 PM

Previous topic - Next topic

hankler

Hello everybody,
I am using report studio 10.2.2 and I am trying to fill a prompt with different values using javascript but I haven't been able to do it.  It does not error out and the prompt does not get updated.  I followed the cognos API but it does not seem to work, I have read that the method addValues() has a bug, is this true? 
I hope you can help me, here is the code that I am using.

<script type="text/javascript">

// Create Report Object
var oCR = cognos.Report.getReport("_THIS_");

function refreshYards() {
try
{
   //Get prompt's info
   var countryPrompt = oCR.prompt.getControlByName("CountryPr");
   var yardCountryPrompt = oCR.prompt.getControlByName("CountryYardPr");

   var selectedValues = countryPrompt.getValues();
   var allOptions = yardCountryPrompt.getValues(true);
   alert(selectedValues.length);
   alert(allOptions.length);   

   for (var i=0; i< selectedValues.length; i++) {
      for (var j=0; j < allOptions.length; j++) {
         var currentRecordId = allOptions[j].use;
         var currentRecordDisplay = allOptions[j].display;
         var countryId = currentRecordDisplay.slice(0,3);
         var yardId = currentRecordDisplay.slice(3,6);
         var yardName = currentRecordDisplay.slice(6).toUpperCase();
         //alert(currentRecordDisplay);
         //alert(countryId);
         //alert(yardId);
         //alert(yardName);
      
         if (selectedValues.use == countryId) {
            alert(yardId);
            alert(yardName);
            var oValues = [{'use': yardId, 'display': yardName}];
            setPromptValue(oCR, 'YardPr', oValues);
         }
         //break;
      }
   }
}
catch(err) {
   alert(err);
}

}
function setPromptValue (objRep, promptName, Value)
{
try {
   alert (promptName + ' - ' + Value[0].use + ' - ' + Value[0].display);
   var yardPrompt = objRep.prompt.getControlByName( promptName );
   yardPrompt.addValues( Value );
   var iniValues = yardPrompt.getValues(true);
   alert (iniValues.length);
}
catch (err) {
   alert(err);
}
}
</script>

dougp

Javascript doesn't generally produce error messages for the person viewing the page.  If it's not producing an error message but not succeeding, it's stopping part way through.  You'll need to open the web development tools in your browser (F12) to troubleshoot.

I have not had any trouble with the Prompt API in 10.2.1 and the basic concept of your code looks good.  There must be a syntax error somewhere that is causing your code to stop running.

hankler

I used the debugger with F12 as you mentioned, I even add alerts to see if it's working fine and the only problem is that does not add the values to the prompt.  Have you ben able to insert values on a prompt using the addValue() method? if so, can you please send me an example so I can replicate it.
Thanks

bdbits

While in the debugger, I would make certain that your variables really are pointing to the controls. Or use the javascript console to try and add to the prompt. This may point to a problem.

hankler

Hello bdbits, i did as you recommended and it did not work, every time  i tried the addValues function it kept saying undefined, i am attaching the print screen.  Do you have a working example of the use of this function in the console fo the debugger?

Regards


bdbits

Here is an example from the documentation for the prompt API, though I suspect you have seen this already.
https://www.ibm.com/support/knowledgecenter/SSEP7J_10.2.1/com.ibm.swg.ba.cognos.ug_cr_rptstd.10.2.1.doc/r_prmpt_api_cognos_prompt_control_addValues.html#cognos.prompt.control.addValues

My guess is that yardPrompt is pointing to a prompt object rather than the control. If your debugger has a DOM browser, I would drill down and find the control and take a look at what is there versus what is inside yardPrompt and see if that points you in the direction of the problem.

While I know javascript at an intermediate level, I've not played much with the prompt API. It didn't exist when I did most of my work with javascript within Cognos.

hankler

Yes, I've already seen that documentation, I even tried the same example and it does not work.  For some reason the value is not added to the prompt.  I've searched all over and I haven't found any example or anybody that have sucessfully used the addValue() funtion.  That is the only thing that I am missing.  If anybody can help me I would appreciated.

Regards