COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: smehnert on 19 Jun 2019 11:33:38 AM

Title: Calendar Prompt setting the 'Last Date' property
Post by: smehnert on 19 Jun 2019 11:33:38 AM
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
Title: Re: Calendar Prompt setting the 'Last Date' property
Post by: CognosPaul on 24 Jun 2019 08:15:52 PM
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.
Title: Re: Calendar Prompt setting the 'Last Date' property
Post by: smehnert on 25 Jun 2019 07:53:26 AM
Paul

It is 10.2.2 :), we are moving to 11, later in the year.
Title: Re: Calendar Prompt setting the 'Last Date' property
Post by: CognosPaul on 25 Jun 2019 12:43:00 PM
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
Title: Re: Calendar Prompt setting the 'Last Date' property
Post by: smehnert on 28 Jun 2019 03:28:57 AM
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

Title: Re: Calendar Prompt setting the 'Last Date' property
Post by: CognosPaul on 28 Jun 2019 10:06:54 AM
setValidator works whenever a value is selected. Are you running into any problems using it?