COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: babu babu on 03 Dec 2010 07:21:47 PM

Title: Dropdown Check box
Post by: babu babu on 03 Dec 2010 07:21:47 PM
Hi,
How can i get dropdown check list in value prompt when i am using multi select option(like gmail labels option).Please let me know.

Thanks!
Anand.
Title: Re: Dropdown Check box
Post by: PRIT AMRIT on 11 May 2011 04:37:15 AM
Have you got a work around for this requirement.

I have a similar requirement. I have a value prompt with multi select. Instead of a 'List Box/Check Box Group' I want the drop down with multiple selection option.

Is it possible?

Thanks
Prit
Title: Re: Dropdown Check box
Post by: Sunchaser on 11 May 2011 05:28:52 PM
Hi all,

Technically and directly from Cognos, I don't know if it is feasible but I would tend to say that it is a kind of "nonsense" (please don't take it against you).
In the "programmatic" point of view, how is it possible to say to the object that the selection is done -> means the user has finished to tick the checkboxes (and he is not only hesitating between two choices for example) and then the object can close the drop-down list ?
Basically with a drop-down list, the user click on an arrow, make one selection in the list, then the drop-down is closed and the value of a variable / parameter (or whatever behind) is updated, and eventually - if existing - a function is called / triggered, etc ...
I'm repeating myself but, I'm really wondering how it could be then possible to indicate to the object that the selections are done; I don't think it would be a "natural" behaviour, even for a user, as most of the time they are used to deal with simple things.

Regards
Vinc.
Title: Re: Dropdown Check box
Post by: PRIT AMRIT on 11 May 2011 10:30:43 PM
Hi Vinc,

Very true and I do agree with you 100% and the same questions came to mind as well. I am just coming from the meeting with Users and convinced them the difficulties would be caused from such functionalities.

We agreed to stick to the simple multi select with List Box option.

Thanks for your valuable suggestions.

Cheers

Prit

Title: Re: Dropdown Check box
Post by: Amruta Gandhi on 19 May 2011 07:10:44 AM
   Although this functionality cannot be achieved directly by Cognos, it can be implemented with the help of JavaScript. If usage of JavaScript is allowed, then following implementation can be used to give the look of a single select prompt to a multiselect prompt.  The Multiselect Prompt here is of List Box type.
   When the user clicks on the drop down of the single select prompt shown in the report, then the corresponding multiselect prompt is seen. After selecting the various parameters from the multiselect prompt it is hidden on the click of any place in the document outside the multiselect prompt.
For example let's create a multi select prompt for selection of Product Line. Paste the following scripts in the positions mentioned as below:
1.   Place the following script in an HTML item Before the Prompt:
<SELECT name="reportDropDownPL" onclick="javascript:changePromptType(this);" readonly style="FONT-SIZE: 10pt; WIDTH: 140px; FONT-FAMILY: 'Arial';display:block">
    <OPTION VALUE="1" SELECTED >Product Line</OPTION>
/*
Note: The term before the 'DropDownPL' (of SELECT tag as above) and 'PromptPL' (Div id of multiselect prompt as below) should be same. In this case it is 'report'.
The SELECT tag here is used to make a single select prompt showing Product Line, with the help of javascript instead of the default cognos value prompt.
This will help save more space in the report.
*/

</SELECT>
<div id="reportPromptPL" style="margin:0px;padding:0px;display:none;position:absolute">
Please Note: For the single select prompt and multiselect prompt to look similar, both should be of the same width. Here, the width in SELECT tag of the above script (which acts as Single select prompt) is 140 px. Hence, define the width of the multiselect prompt as 140 px through the size and overflow option of the prompt. Also, take care to hide the adornments of multiselect prompt. Depending on the requirement, set the Required property of the prompt to 'Yes' or 'No'. It is desirable to provide the default selection to the prompt.

2.   Place the end tag for div in an HTML item After the prompt </div> 

3.   Place an HTML item at the starting i.e. before the HTML item of the starting of the Prompt and paste the script as below in it. Here, the function showHideMultiSelectPrompt along with function changePromptType is used to give a look of combo box for the prompts. It typically displays and hides the multiselect prompt on the click of single select prompt seen in the report.
<script>
var fW = (typeof getFormWarpRequest == "function" ? getFormWarpRequest() : document.forms["formWarpRequest"]);
if ( !fW || fW == undefined) { fW = ( formWarpRequest_THIS_ ? formWarpRequest_THIS_ : formWarpRequest_NS_ );}

var expPromptDivName ="PL";
var expPromptName = "reportPromptPL"; //assign the div id of the multiselect prompt of report to this expPromptName variable. Here it is reportPromptPL.


// function for displaying multiselect drop down prompt --------------------------------------

function showHideMultiSelectPrompt(){
   var clickObj = event.srcElement;   
   if(clickObj && clickObj.name && clickObj.name.match('[a-z]+DropDown'+expPromptDivName )){
      var promptName = clickObj.name.match(/([a-z]+)DropDown([A-Z]{2})/)[1];
      var multiSelectPrompt = document.getElementById(promptName+'Prompt'+expPromptDivName);
      if(multiSelectPrompt.id == expPromptName){
         multiSelectPrompt.style.display = multiSelectPrompt.style.display=="none"?"block":"none";
      }else{
         multiSelectPrompt.style.display = "block";
         document.getElementById(expPromptName).style.display = "none";
         expPromptName = multiSelectPrompt.id;
      }
   }else if(clickObj && clickObj.type != 'select-multiple')
      document.getElementById(expPromptName).style.display = "none";
}

function changePromptType(oPrompt){
   if(oPrompt.multiple == false){
      oPrompt.multiple = true;
      oPrompt.multiple = false;
   }
}

document.onclick=showHideMultiSelectPrompt; //function called to hide the multiselect prompt, when clicked anywhere on the page.
</script>
4.   The above implementation does not hide the default Cognos option of 'Select all Deselect all' seen below the multiselect prompt. It is recommended to hide these options to give a better look and feel of the implementation. To hide these options you may use the following CSS script. Paste the below script in an HTML Item placed on the report.
<STYLE Type="Text/CSS">
DIV.clsPromptComponent DIV A{
   display:none;
}
</STYLE>
Please let me know if anything else is needed or the solution was helpful.


                                                     
Title: Re: Dropdown Check box
Post by: PRIT AMRIT on 23 May 2011 01:20:20 AM
hi Amruta,

A pretty smart work around . I have tried to do a sample as per the steps provided by you. It works fine.

Since I don't have much JS knowledge, Instead of 'List box', can we make it 'Check box group'?

Thanks
Prit
Title: Re: Dropdown Check box
Post by: Amruta Gandhi on 23 May 2011 03:33:46 AM
Thanks Prit,

The above script can be used for a checkbox type prompt too. Just try changing the UI of the Prompt from ListBox to CheckBox. You may require to set the width of the prompt accordingly (both the Cognos Checkbox prompt and the width as mentioned in the SELECT tag).  Please let me know if you face any issues.

Title: Re: Dropdown Check box
Post by: PRIT AMRIT on 23 May 2011 04:28:12 AM
Hi Amrutha,

I had tried so and it's working also fine but the problem is the moment I select one value from 'Multi Select' check box, it closes and doesn't allow me to do multi select at a time. So I have to click several time in order to make multi selection.

Any clue?

Thanks

Title: Re: Dropdown Check box
Post by: Sunchaser on 24 May 2011 04:29:28 PM
Hi all,

I would tend to say that the main problem is that when you click on a checkbox, you "activate" the onclick event of the document, which is at a higher level than the checkbox prompt.
Then it will be necessary to override the onclick event of this object in order to avoid the event to be seen at document level.
In the same time, a "setTimeOut" (or equivalent) event could be put after each click on the checkbox in order to hide the object only - for example - one second after the click, in order to let to the user the possibility to do an other selection.
Title: Re: Dropdown Check box
Post by: Amruta Gandhi on 25 May 2011 01:17:23 AM
Hi Prit,
The problem is due to the document.onclick which calls the function when we click anywhere outside the prompt as rightly suggested by Sunchaser. So, to overcome this we can have an option where in, the Prompt would open and hide on the click of the single select prompt seen on the report. Not much to be done for that, just remove the line "document.onclick=showHideMultiSelectPrompt; " from the script.
Add the statement "showHideMultiSelectPrompt();"   in the changePromptType function as shown below:

function changePromptType(oPrompt){
   if(oPrompt.multiple == false){
      oPrompt.multiple = true;
      oPrompt.multiple = false;
   }
showHideMultiSelectPrompt();
}


This would show the multiselect prompt on the click of the single select prompt and hide it only when it is clicked on that prompt again. However, it would not Hide the multiselect prompt when it is clicked anywhere on the screen.
Please let me know if I was able to solve your query.
Title: Re: Dropdown Check box
Post by: kiran04 on 25 May 2011 09:40:04 AM
Hi Amrutha,
I had a similar kind of issue where i have two promptsi.e, the first is a dropdown list and second is check box .
The drop down has 4 values and check box has 1 value. Here the condition is I have to display the checkbox for only 1 value of the dropdown list and for the others it should not display. So,
what I have done is I took a conditional variable and used conditional block for that check box prompt. It is working fine but the issue is as it was a cascaded prompt ,.. i used autosubmit is equal to on..so for that ..the other conditions where i should not display the checkbox..there the report is running without hitting the run button..
I got a solution for this to keep a reprompt button in between the checkbox and run button .
but the user requirement doesn't permit me to do that..
so is there any way the java script can help me??
Title: Re: Dropdown Check box
Post by: Amruta Gandhi on 26 May 2011 11:14:32 AM
Hello KWASO4,
Replicating your requirement I created a report with a single select value prompt for "Product Line", check box prompt for "Year", a "FINISH" button and a "List". The checkbox for year is pointed to Year query and contains only one value of 2005, in line to your requirement. This checkbox would be seen only when the Product Line "Mountaineering Equipment" is selected in the Product Line prompt.
For the Product Line prompt two conditions are to be noted:
1.   Auto Submit is made off
2.   Name of the Product Line prompt is specified as ProductLine. This name is used in the script hence needs to be followed. In case this is changed, the corresponding place where it is used, also should be changed accordingly (Similar comments are added in the place where it is used).
A FINISH button is added to apply the Prompt selections.
There is a list which contains Product Line, Year and Revenue. When any other Product Line except Mountaineering Equipment is selected, the list shows data for all the years for corresponding Product Line. When "Mountaineering Equipment" is selected AND "2005" is checked, then list filters for both the selections, else it filters for only Product Line. In the list query, the following filter condition is added besides the Product Line filter ([Product line code]=?PL?):
if (?PL?=992)
then ([Year]=?Prod?)
else (1=1)

This filter is made optional as it has to be applied only when the Year prompt is checked. Here, in the If condition (i.e. at the place of 992) specify the ID/Value of the selection for which the checkbox filter has to be applied.
Following are the places specified where script needs to be added in HTML Tags:
1. Before the Value Prompt of Product Line add the following script:
<script>
var fW = (typeof getFormWarpRequest == "function" ? getFormWarpRequest() : document.forms["formWarpRequest"]);
if ( !fW || fW == undefined) { fW = ( formWarpRequest_THIS_ ? formWarpRequest_THIS_ : formWarpRequest_NS_ );}


function HideShowPrompt()
{
   var objDiv= document.getElementById("parentPrompt");
   var objOptions = objDiv.getElementsByTagName("OPTION");
//In the following script a loop is driven to check each selection of prompt and match it with desired value. When the desired value is met the checkbox prompt would be seen, else it would be hidden.
   for (i=0;i<objOptions.length;i++)
   {
      if (objOptions.selected == true)
      {
         if(objOptions.innerText== "Mountaineering Equipment") //specify the name of the selection, for which you need to show the checkbox prompt. Here it is Mountaineering Equipment.
         {
            document.getElementById("childPrompt").style.display="block";

         }
         else
         {
            document.getElementById("childPrompt").style.display="none";

         }
      }
   }
}
</script>
<div id="parentPrompt" >

2. After the Product Line Prompt add
</div>
3. Before the checkbox prompt add:
<div id="childPrompt" style="display:none">
4. After the checkbox prompt add:
</div>

<script>

fW._oLstChoicesProductLine.onchange= function (){HideShowPrompt();}
/*Here, the function HideShowPrompt is called when the selection of the Parent Prompt is changed.
Please Note: The term "ProductLine" adjoined to the "fW._oLstChoices" is the name of the prompt specified.
In case of change in the name take care to specify the corresponding name of prompt here as well.*/

/*The following script will check if the checkbox prompt is hidden or shown on page load, and will keep the same when clicked on the Finish Button*/

   var objDivCheck= document.getElementById("parentPrompt");
   var objOptionsCheck = objDivCheck.getElementsByTagName("OPTION");
   for (i=0;i<objOptionsCheck.length;i++)
   {
      if (objOptionsCheck.selected == true)
      {
         if(objOptionsCheck.innerText== "Mountaineering Equipment") //specify the name of the selection, for which you need to show the checkbox prompt. Here it is Mountaineering Equipment.
         {
            document.getElementById("childPrompt").style.display="block";

         }
         else
         {
            document.getElementById("childPrompt").style.display="none";

         }
      }
   }
</script>


Attached is the xml of the test report named HideShowPrompt. Please modify the package if needed.

Kindly let me know if anything else is needed or if the solution was helpful.

Title: Re: Dropdown Check box
Post by: PRIT AMRIT on 30 May 2011 01:09:48 AM
Great piece of work Amruta.... Keep it up.... 8)
Title: Re: Dropdown Check box
Post by: kiran04 on 30 May 2011 09:17:25 PM
Hi Amrutha,
Thanks alot.. for the detailed explanation of the functionality of javascript  and I did my functionality by using validate function.. It worked.

var stsList =  fW._oLstChoiceStatus;/***Here Status is the name for the first prompt****/
fW._oLstChoicesStatus.onchange = validateChkBox;
stsList .options[1].selected = true;

function validateChkBox(){
         if(stsList .options[1].selected || stsList .options[3].selected || stsList .options[4].selected )
        {
                 document.getElementById("ChkBx").style.display = "none";
        }else{
               document.getElementById("ChkBx").style.display = "";
               fW._oLstChoicesunclProperty.checked= false
       }
</script>
<script>
validateChkBox();
</script>


Anyway..thanks again for the great explanation..
Thanks,
KWAS04.
Title: Re: Dropdown Check box
Post by: Amruta Gandhi on 31 May 2011 12:14:47 AM
Thanks all for your appreciation! :)
Title: Re: Dropdown Check box
Post by: kiran04 on 17 Jun 2011 03:58:42 PM
Hi Amrutha,
I'm having another issue with the prompts in the report page. can u suggest me if javascript may help in this one.
The issue is that I'm having two value prompts in the report page as well as in the prompt page. They are cascaded prompts and they are working fine in prompt page but in the report page, when the first prompt is selected , it is directly running the report without hitting the finish button. But it is picking up the value in the second prompt.
note:
the two value prompts here are --required
the autosubmit is kept 'yes' for the first prompt in both the pages.
please , reply me with your suggestions to resolve this issue.
Title: Re: Dropdown Check box
Post by: Vish on 21 Jul 2011 12:54:09 AM
Thanx Guys...Its really COOL 8)
Title: Re: Dropdown Check box
Post by: Amruta Gandhi on 21 Jul 2011 04:49:36 AM
Hi KWAS04,

Sorry for being so late to see this...
Can you tel me what kind of filter is applied to the report? If report contains filter for only the second prompt then this might not occur. Also, the Autosubmit should be "No" for the second prompt.
Besides this, are both the prompts exactly same in the Report Page and the Prompt page? Coz if this is the case, then why should there be a reason to have the Prompt page separately? The users can select the prompts from the report page itself and execute the report. Please let me know if I have missed out anything.
Title: Re: Dropdown Check box
Post by: kiran04 on 27 Jul 2011 04:22:57 PM
Hi Amrutha,
Yes,  your right , the user wants to run the report in report page itself without going back to prompt page, that is the requirement. Any how, I resolved the problem.

Please go through the below link
http://www.cognoise.com/community/index.php/topic,14735.msg46766.html#msg46766
There, you can check the details of the issue and  the solution.
And anyway thanks for replying back to me.

Thanks,
KWAS04.
Title: Re: Dropdown Check box
Post by: xplorerdev on 31 Jul 2013 04:31:19 AM
Hi Amruta,

Very informative post. Thanks a lot.

My report has 5 check box value prompts, one below the other. I have followed your comments and have pasted the HTML items and the corresponding codes within them. The first Prompt is working fine. I click on it, it gives a list of values with check boxes, I select multiple values from that list. Its all OK. BUT when I click on the second prompt, it again opens the first prompt. Similarly, when I click on 3rd, 4th or 5th prompt, it still opens up the first prompt. It seems that whenever a Value Prompt is clicked on, it opens the first Value Prompt.

Am I doing something wrong? Or the code is meant only for 1 Value Prompt? If that is the case then what I should probably do to make multiple Value Prompts functional?

Kindly advice.

Thanks n Regards
Dev
Title: Re: Dropdown Check box
Post by: CognosPaul on 31 Jul 2013 04:54:03 AM
I had a similar requirement not too long ago. My solution was slightly different, but will work well with multiple prompts.

Check out the post I wrote for PerformanceG2: http://performanceg2.com/2013/07/01/animated-drop-down-prompts-in-cognos/


If you're not on 10.2, you should be able to downgrade the report by changing "developer.cognos.com/schemas/report/10.0" to "developer.cognos.com/schemas/report/8.0"
Title: Re: Dropdown Check box
Post by: xplorerdev on 01 Aug 2013 12:16:38 AM
Hi PaulM,

You're the man. Thanks a lot. Your technique at http://performanceg2.com/2013/07/01/animated-drop-down-prompts-in-cognos/ works like a charm.  :)

Best Regards
Dev
Title: Re: Dropdown Check box
Post by: frankrss on 26 Sep 2013 04:25:29 AM
I have two questions:

1. If I have more than 2 prompt lists, how can I use the scripts posted on this thread?
2. for this link:  http://performanceg2.com/2013/07/01/animated-drop-down-prompts-in-cognos  , i can not download the files that mentioned there.

Thanks
Title: Re: Dropdown Check box
Post by: CognosPaul on 29 Sep 2013 08:29:06 AM
The links seem to work for me. They are txt files, so your browser may be attempting to do something weird with them. Try right click - save as. If that still doesn't work, I'll attach them to a post here.
Title: Re: Dropdown Check box
Post by: Michael75 on 30 Sep 2013 02:28:42 AM
I can access Paul's PerformanceG2 article, via a slightly different URL:

http://www.performanceg2.com/blog/animated-drop-down-prompts-cognos/ (http://www.performanceg2.com/blog/animated-drop-down-prompts-cognos/)

Note that there's no "in-" before "cognos". Strange...

HTH
Michael
Title: Re: Dropdown Check box
Post by: frankrss on 30 Sep 2013 08:48:53 AM
Hi Paul,

I tried to save as, there is nothing. It seems not only for me, somebody left a comment there with the same problem.

Thanks
Title: Re: Dropdown Check box
Post by: frankrss on 30 Sep 2013 09:46:52 AM
sorry, I still  have a question about the drowdown multi selection scripts posted on the thead. It works now perfect with me even with more than one dropdown on one page, now I would like to know whether it can get the selected value as texts in the selections part, or just give a hint text there in the selection( for example: if there are items selected, then it will show: items selected as text instead of the fixed text there:
<OPTION VALUE="1" SELECTED >Product Line</OPTION>
in fact what I mean is: to give Product Line a dynamic Variable based on what you have chosen.
Title: Re: Dropdown Check box
Post by: ShadowOfTheRiver on 04 Mar 2014 06:33:08 AM
@franks How do you get it for multiple prompts? Any added prompt doesn´t work for me! apreciate your assistance
Title: Re: Dropdown Check box
Post by: CognosPaul on 05 Mar 2014 08:59:11 AM
Wow, I missed Franks message. Frank, if you still need help, let me know.

Shadow, it should work fine for multiple prompts. You only need to add another call to runPromptPopup for each prompt you need to change. Remember, it only supports list, radios, and checkbox prompts. Also, make sure that the prompts have a name. The javascript works by calling the object name.

So if I have two prompts, OrderMethod and Year it would be:
paulScripts.runPromptPopup ('OrderMethod','All Order Methods');
paulScripts.runPromptPopup ('Year','All Years');
Title: Re: Dropdown Check box
Post by: zzeuss on 06 May 2014 07:54:20 AM
Quote from: Amruta Gandhi on 25 May 2011 01:17:23 AM
Hi Prit,
The problem is due to the document.onclick which calls the function when we click anywhere outside the prompt as rightly suggested by Sunchaser. So, to overcome this we can have an option where in, the Prompt would open and hide on the click of the single select prompt seen on the report. Not much to be done for that, just remove the line "document.onclick=showHideMultiSelectPrompt; " from the script.
Add the statement "showHideMultiSelectPrompt();"   in the changePromptType function as shown below:

function changePromptType(oPrompt){
   if(oPrompt.multiple == false){
      oPrompt.multiple = true;
      oPrompt.multiple = false;
   }
showHideMultiSelectPrompt();
}


This would show the multiselect prompt on the click of the single select prompt and hide it only when it is clicked on that prompt again. However, it would not Hide the multiselect prompt when it is clicked anywhere on the screen.
Please let me know if I was able to solve your query.

Hi Amruta,

This is an old post.. and hope you can help me out here.. :)
Would there be a way to hide the multiselect prompt only when you click outside of the prompt box?
We want the multiselect dropdown open so we can select more than one values.. but instead of clicking the prompt, we want the dropdown go away when you click outside of that prompt..
Than you!!
Title: Re: Dropdown Check box
Post by: ranjaniganesh30 on 05 Nov 2014 06:49:07 AM
Hi,

The given javascript is not working in Firefox. Can someone help?
Title: Dropdown Check box
Post by: Cinderellapong on 27 Feb 2015 02:26:08 PM
Hi Amruta,
Very impressed by your response and it solved my issue too! Thanks so much! But I have one more question, we have a lot of prompts in the report. I want to apply this method to each prompt, but seems it only works for one prompt, do you know why? I also changed the div ID for each of them..
Thanks in advance!