COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: cognosdelaware on 13 Jul 2017 01:08:29 PM

Title: How can I clear a Multi-Select and Multi-Line Text Box Prompt Choices?
Post by: cognosdelaware on 13 Jul 2017 01:08:29 PM
Hi,

  I have a Text Box Prompt with the "Multi-Select" and "Multi-Line" properties set to Yes.

  When I enter some values in the Text Box Prompt, click "Insert", they populate the "Choices:" box next to the "Insert" button, is there a way to clear these values in javascript(Clear the values under the "Choices:" area)?

Thanks
Title: Re: How can I clear a Multi-Select and Multi-Line Text Box Prompt Choices?
Post by: BigChris on 14 Jul 2017 02:14:43 AM
Below the list of choices there's a Select All option. Click that then click remove...
Title: Re: How can I clear a Multi-Select and Multi-Line Text Box Prompt Choices?
Post by: cognosdelaware on 14 Jul 2017 09:44:07 AM
I meant through JavaScript
Title: Re: How can I clear a Multi-Select and Multi-Line Text Box Prompt Choices?
Post by: BigChris on 17 Jul 2017 01:09:59 AM
I know you did, but I don't understand why you'd go to the hassle of saving a single mouse click. You could write something that then breaks in the next release of Cognos...
Title: Re: How can I clear a Multi-Select and Multi-Line Text Box Prompt Choices?
Post by: cognosdelaware on 17 Jul 2017 06:49:45 AM
The reason is, that I have two types of these controls and based off a radio button selection, when the user goes between both, I want to clear the one they did not chose, otherwise it would run the report with choices in both controls.
Title: Re: How can I clear a Multi-Select and Multi-Line Text Box Prompt Choices?
Post by: hespora on 17 Jul 2017 09:10:54 AM
if that is the goal, i'd achieve that differently:

- create a boolean variable
paramcount('pPrompt1') > 0
and
paramcount('pPrompt2') > 0

- create a new report page with a static text explaining that the user should not have choices in both prompts
- set the variable above as the render variable for this page in case of true value
- set the variable above as the render variable for your actual report page in case of false value
Title: Re: How can I clear a Multi-Select and Multi-Line Text Box Prompt Choices?
Post by: BigChris on 18 Jul 2017 01:48:59 AM
You don't need to clear the other prompt...if you write your filter correctly it'll be ignored anyway - something along the lines of:

(?pRadioButton? = '1stOption' and [Field1] in ?p1stPrompt?) or (?pRadioButton? = '2ndOption' and [Field2] in ?p2ndPrompt?)
Title: Re: How can I clear a Multi-Select and Multi-Line Text Box Prompt Choices?
Post by: cognosdelaware on 19 Jul 2017 06:48:01 AM
My issue is that I have 3 controls:

1) Value Prompt with 2 static choices displayed as Radio button group
    1(This is the Use value) and "Choice1" (This is the Display value of the first radio button)
    2(This is the Use value) and "Choice2" (This is the Diplay value of the second radio button)

2) Text Box Prompt with parameter value called "parmCusip" and Name property called "CUSIP"
3) Text Box Prompt with parameter value called "parmAccountNumber" and Name property called "ACCOUNTNUMBER"

When "Choice1" radio button is selected the "ACCOUNTNUMBER" Text Box Prompt should have it values cleared(values under the  "Choices:" area), this is in case a user entered a series of Account Numbers.

Vice-Versa for "Choice2"
Title: Re: How can I clear a Multi-Select and Multi-Line Text Box Prompt Choices?
Post by: CognosPaul on 19 Jul 2017 10:17:25 PM
If I understand, the user can filter on one of two possibilities - CUSIP or ACCOUNTNUMBER. That choice is driven through the use of the radio prompt.

Is the requirement to clear and disable the prompt to prevent the filter from activating? Why not make the prompt value part of the filter logic? If you're using DQM mode, you can do something like:

#
prompt('Choice','token')
when 'Choice1' then '[Namespace].[Dim].[CUSIP] in ' + promptmany('CUSIP','string','NA')
when 'Choice2' then '[Namespace].[Dim].[ACCOUNTNUMBER] in ' + promptmany('ACCOUNTNUMBER','string','NA')
else '1=2' /*invalid choice, someone is playing games*/
#


That way only the correct filter will ever be used, even if both prompts have values.

If you must clear the prompt you can do something like:


<script>
var paulScripts ={}
  , oCR = cognos.Report.getReport("_THIS_");

paulScripts.getControl = function(promptName) {
  return oCR.prompt.getControlByName(promptName);
};


paulScripts.getControl('ChoicePrompt').setValidator(function(values){
var choice = values[0].use;

if(choice=='Choice1') {
  paulScripts.getControl('ACCOUNTNUMBER').clearValues();
  paulScripts.getControl('ACCOUNTNUMBER')["@disabled"]=true;
  paulScripts.getControl('CUSIP')["@disabled"]=false;
}
if(choice=='Choice2') {
  paulScripts.getControl('CUSIP').clearValues();
  paulScripts.getControl('ACCOUNTNUMBER')["@disabled"]=false;
  paulScripts.getControl('CUSIP')["@disabled"]=true;
}

});

</script>


The flags are not currently supported in Cognos Analytics, but there is an easy way to access the element through the Prompt API. If you're looking to upgrade the JavaScript will be difficult, but not impossible, to adapt.
Title: Re: How can I clear a Multi-Select and Multi-Line Text Box Prompt Choices?
Post by: cognosdelaware on 20 Jul 2017 07:57:51 AM
I ended up doing the following that works and for others in case they need it:

When a user clicks on the other radio button, this code fires on the click event:

var oCR = cognos.Report.getReport("_THIS_");
var myPrompt = oCR.prompt.getControlByName("CUSIP"); //for the control, you need to have its NAME property set
myPrompt.clearValues();

Thanks for all the help.