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

Offline Kiran Kandavalli

  • Community Leader
  • *****
  • Join Date: Jun 2011
  • Posts: 100
  • 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,734
  • Forum Citizenship: +256/-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: 100
  • 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,734
  • Forum Citizenship: +256/-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: 100
  • 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.

 


       
Twittear