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
Are you looking for interactive or non-interactive mode?
Thanks for your response Paul!
I am looking for Non-Interactive mode.
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.
Thank you so much Paul! the solution is working.
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?
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"}
Is this a custom control JS file Paul ?
It is, but I have noticed a problem. using this script will fail when typing into the edit box. Still needs some work.