COGNOiSe.com - The IBM Cognos Community

IBM Cognos Analytics Platform => Cognos Analytics => Reporting => Topic started by: Kiran Kandavalli on 21 Jul 2018 12:39:48 PM

Title: How to autosubmit Cognos Date prompt using JavaScript
Post by: Kiran Kandavalli on 21 Jul 2018 12:39:48 PM
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
Title: Re: How to autosubmit Cognos Date prompt using JavaScript
Post by: CognosPaul on 22 Jul 2018 10:35:37 PM
Are you looking for interactive or non-interactive mode?
Title: Re: How to autosubmit Cognos Date prompt using JavaScript
Post by: Kiran Kandavalli on 22 Jul 2018 11:21:29 PM
Thanks for your response Paul!

I am looking for Non-Interactive mode.


Title: Re: How to autosubmit Cognos Date prompt using JavaScript
Post by: CognosPaul on 23 Jul 2018 09:23:28 AM
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.
Title: Re: How to autosubmit Cognos Date prompt using JavaScript
Post by: Kiran Kandavalli on 24 Jul 2018 11:28:36 PM
Thank you so much Paul! the solution is working.
Title: Re: How to autosubmit Cognos Date prompt using JavaScript
Post by: JuanGonzalezT on 21 Dec 2018 07:45:31 AM
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?
Title: Re: How to autosubmit Cognos Date prompt using JavaScript
Post by: CognosPaul on 07 Jan 2019 02:17:40 PM
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"}
Title: Re: How to autosubmit Cognos Date prompt using JavaScript
Post by: oscarca on 08 Jan 2019 05:43:28 AM
Is this a custom control JS file Paul ?
Title: Re: How to autosubmit Cognos Date prompt using JavaScript
Post by: CognosPaul on 08 Jan 2019 09:44:40 AM
It is, but I have noticed a problem. using this script will fail when typing into the edit box. Still needs some work.