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

How to autosubmit Cognos Date prompt using JavaScript

Started by Kiran Kandavalli, 21 Jul 2018 12:39:48 PM

Previous topic - Next topic

Kiran Kandavalli

Team,

I have a requirement to autosubmit the Cognos Date prompt without using Prompt Buttons.

if anyone has the code, can you please provide it to me.

Thanks!
Kiran

CognosPaul

Are you looking for interactive or non-interactive mode?

Kiran Kandavalli

Thanks for your response Paul!

I am looking for Non-Interactive mode.



CognosPaul

HTML Item 1. <script>
var paulScripts = {}
  , oCR = cognos.Report.getReport("THIS")
  , gateway = window['oCV'+'_THIS_'].getRV().getCV().sGateway;

// UTILITY FUNCTIONS
/*
* function Scripts.getControl
* Simply returns the prompt control.
*/

paulScripts.getControl = function(promptName)   {
    return oCR.prompt.getControlByName(promptName);
  };

</script>


That should go at the top of the report, ideally in the page header.


HTML Item 2:
<script>
paulScripts.getControl('datePrompt').setValidator(
  function(values) {
    paulScripts.getControl('datePrompt').setValidator(function(values){oCR.sendRequest( cognos.Report.Action.REPROMPT
);});
return true;
  }
);
</script>


That should go immediately after your prompt. Make sure you replace datePrompt with the name of your date prompt.

The reason it has two setValidators in there is because the setValidator function is triggered on the page load. If it had the submit function in that, you'd end up with an infinite cycle of page loading and refreshing.

Kiran Kandavalli

Thank you so much Paul! the solution is working.

JuanGonzalezT

Quote from: CognosPaul on 22 Jul 2018 10:35:37 PM
Are you looking for interactive or non-interactive mode?
Hi Paul, i'm searching for the same but in interactive mode, could you help me with this, please?

CognosPaul

For some reason calendars don't trigger the setValidator. I still can't figure out a good way around that.

Edit box date prompts work great though. Use the following:

define( [], function(  ) {
"use strict";


function DateAutoSubmit(){};

DateAutoSubmit.prototype.initialize = function( oControlHost, fnDoneInitializing )
{
  var o = oControlHost.configuration
  , ctrl =  o["promptName"];
 
   

  oControlHost.page.getControlByName(ctrl).setValidator(
 
   function(values){
    oControlHost.page.getControlByName(ctrl).setValidator(function(values){
      oControlHost.finish();
      return true;
     
      }
     
      );

     return true;
   }
  );         
     
fnDoneInitializing();

};

return DateAutoSubmit;
});


In the config make sure to use
{"promptName":"date prompt name"}

oscarca


CognosPaul

It is, but I have noticed a problem. using this script will fail when typing into the edit box. Still needs some work.