Hi All,
I have been racking my brains trying to find a way to restrict users from selecting a dates (from a point in time) using the calendar prompt. This can be done using the calendar property 'Last Date' but this is a static value. So I have looked for the object name so I can change this using javascript, but I can find it anywhere!
Please help :'(
Regards
Simon
Is this Cognos 10.2 or later? What are your plans on upgrading to Cognos 11? Any solutions I give you for C10 will only work in non-interactive mode on C11.
Paul
It is 10.2.2 :), we are moving to 11, later in the year.
There is a lastDate property, but changing it doesn't do anything unfortunately. You'll need to use setValidator to check and set the value.
Take a look at this and modify as needed:
<script>
var paulScripts ={}
, oCR = cognos.Report.getReport("_THIS_")
paulScripts.getControl = function(promptName) {
return oCR.prompt.getControlByName(promptName);
};
var maxDateString = '2019-06-25';
var maxDate = function(values){
//if nothing is selected don't do anything
if(!values.length) return true;
var ctrl = paulScripts.getControl(this["@name"])
, maxDateInt = parseInt(maxDateString.replace(/-/g,''))
, selDateInt = parseInt(values[0].use.replace(/-/g,''));
console.log('testing ' + selDateInt + ' - ' +maxDateInt);
if(selDateInt>maxDateInt){
console.log('Failed test, date is higher than ' + maxDateInt);
ctrl.setValidator();//remove the validator to stop the loop;
ctrl.setValues([{'use':maxDateString}]);
ctrl.setValidator(maxDate);
}
return true;
}
</script>
<script>
paulScripts.getControl('datePrompt').setValidator(maxDate);
</script>
The last script should go after the prompt object. I've hardcoded the max date there, but there are a lot of ways of making it data driven if you want. Stick the date into a value prompt and call it with something like: maxDateString=paulScripts.getControl('maxDatePrompt').getValues(true)[0].use
good luck
Hi Paul,
Thank you for the reply...
This function only evaluates the date on initial loading of the page, so its not done when a date is actually selected?
Regards
Simon
setValidator works whenever a value is selected. Are you running into any problems using it?