Author Topic: How to autosubmit Cognos Date prompt using JavaScript  (Read 586 times)

Offline Kiran Kandavalli

  • Community Leader
  • *****
  • Join Date: Jun 2011
  • Posts: 101
  • Forum Citizenship: +0/-0
How to autosubmit Cognos Date prompt using JavaScript
« 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

Online CognosPaul

  • Global Moderator
  • Statesman
  • *****
  • Join Date: Jan 2009
  • Posts: 1,766
  • Forum Citizenship: +257/-1
    • Paul's Cognos Blog
Re: How to autosubmit Cognos Date prompt using JavaScript
« Reply #1 on: 22 Jul 2018 10:35:37 pm »
Are you looking for interactive or non-interactive mode?

Offline Kiran Kandavalli

  • Community Leader
  • *****
  • Join Date: Jun 2011
  • Posts: 101
  • Forum Citizenship: +0/-0
Re: How to autosubmit Cognos Date prompt using JavaScript
« Reply #2 on: 22 Jul 2018 11:21:29 pm »
Thanks for your response Paul!

I am looking for Non-Interactive mode.



Online CognosPaul

  • Global Moderator
  • Statesman
  • *****
  • Join Date: Jan 2009
  • Posts: 1,766
  • Forum Citizenship: +257/-1
    • Paul's Cognos Blog
Re: How to autosubmit Cognos Date prompt using JavaScript
« Reply #3 on: 23 Jul 2018 09:23:28 am »
HTML Item 1.
Code: [Select]
<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:
Code: [Select]
<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.

Offline Kiran Kandavalli

  • Community Leader
  • *****
  • Join Date: Jun 2011
  • Posts: 101
  • Forum Citizenship: +0/-0
Re: How to autosubmit Cognos Date prompt using JavaScript
« Reply #4 on: 24 Jul 2018 11:28:36 pm »
Thank you so much Paul! the solution is working.

Offline JuanGonzalezT

  • Associate
  • **
  • Join Date: Dec 2018
  • Posts: 4
  • Forum Citizenship: +0/-0
Re: How to autosubmit Cognos Date prompt using JavaScript
« Reply #5 on: 21 Dec 2018 07:45:31 am »
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?

Online CognosPaul

  • Global Moderator
  • Statesman
  • *****
  • Join Date: Jan 2009
  • Posts: 1,766
  • Forum Citizenship: +257/-1
    • Paul's Cognos Blog
Re: How to autosubmit Cognos Date prompt using JavaScript
« Reply #6 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:

Code: [Select]
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
Code: [Select]
{"promptName":"date prompt name"}

Offline oscarca

  • Community Leader
  • *****
  • Join Date: Jul 2018
  • Posts: 110
  • Forum Citizenship: +0/-0
Re: How to autosubmit Cognos Date prompt using JavaScript
« Reply #7 on: 08 Jan 2019 05:43:28 am »
Is this a custom control JS file Paul ?

Online CognosPaul

  • Global Moderator
  • Statesman
  • *****
  • Join Date: Jan 2009
  • Posts: 1,766
  • Forum Citizenship: +257/-1
    • Paul's Cognos Blog
Re: How to autosubmit Cognos Date prompt using JavaScript
« Reply #8 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.

 


       
Twittear