If you are unable to create a new account, please email support@bspsoftware.com

 

Cognos 8.4.1 JavaScript question: Default selection for a checkbox prompt list

Started by dtopicMedV, 11 Jan 2011 02:12:43 PM

Previous topic - Next topic

dtopicMedV

Hi,

I have several dashboard reports created in Report Studio (C8.4.1).
There is no prompt page; all prompts are on the report page itself.
I have a checkbox multi-select prompt list that can't figure out.
When report is executed, how can I set dynamically, first element in the list to be checked?

Thanks a lot in advance! 

Arsenal

I'm no JS guy, but check the following link. Point 7 contains a solution to your problem of prompts on the report page.

https://www-304.ibm.com/support/docview.wss?uid=swg21342809

Alternatively, if you can live with auto submit set on each of the prompts then you can add in the following script (i copied it from elsewhere) in an HTML item after each value prompt. Change Prompt1 to appropriate names that you use for your prompt boxes, i.e. you must first name all your prompt boxes first such as A, B, C etc. and then change Prompt1 to A, B, C etc. before adding it in an HTML item after each prompt and then set the prompt's auto submit property to yes. Be aware that if you have 3-4 prompts, then each time a user changes the value of one prompt the report will automatically run without giving the chance to change another prompt value. So, each report run = one and only one prompt change allowed.

<script language="javascript">
var f = getFormWarpRequest();
var list = f._oLstChoicesPrompt1;

list.remove(1);
list.remove(0);
list.removeAttribute("hasLabel");
</script>

All are 8.3 scripts but should work in 8.4

dtopicMedV

Code you provided from IBM support didn't work.
However, your code partially worked, THANK YOU VERY MUCH.
As you can see Product Group prompt has third item selected by default.
Problems with this code:
1. doesn't work for check-box group prompt, only for a list box.
2. it doesn't validate if there are items in the list that are already selected.
I want to force selection only if nothing has been selected.

<script language="javascript">
var f = getFormWarpRequest();
var list = f._oLstChoicesProductGroup;
list[2].selected=true
</script>

dtopicMedV

So, this code will scan list box and if and only if nothing is selected , it will select by default third element in the list box.
But, my question is:
Is there any way to make this code work for check box group prompt, too?

Thanks a lot in advance!

<script language="javascript">
var f = getFormWarpRequest();
var list = f._oLstChoicesProductGroup;
var Counter = 0;
var ii;
for ( ii = 0; ii < list.length; ii++)
{
    var node = list[ii];
    if (node.checked) { Counter++; }
}
if ( Counter < 1)
{list[2].selected=true}
</script>

Arsenal

I wish I could help you but my JS skills are very limited  :-\

Thinking about it, would it help your situation to have static choice check box prompts? You won't need to use a JS then and since there are no prompt pages it's certain that the users can't make a choice in the prompt till the report actually loads. So, you could have a default choice within your static choice box so it runs for that default choice and then your users can make their choice and re run. You could also spoof an All option so the report initially runs for everything and then the users can pick their choice. Of course, if you have like 40 options to select in the prompt or values that change periodically then static choice would be too tedious to make.

MFGF

I can't even spell SJ! :D

Sorry - I do try very hard to avoid javascript - it's my secondary goal in life.

MF.
Meep!

melee

This is mainly for Googlers, but I hope it helps you as well dtopicMedV. Here's how I was able to manipulate a checkbox on a prompt page.

First and foremost, I am a UI designer first and a BI developer second, so these things (checkboxes on a report page) are very important to me. If you haven't yet, please check out my post about getting jQuery running on your report. This will cut down your JS interaction time dramatically.

http://nicbertino.com/?p=16

Once you have that basic setup, use two HTML items around your checkbox - the first one should be:

<div id="checkbox>

and the one after it should be:

</div>

Place another HTML item to the right of the report title at the very top. Put your basic code in there, it should resemble something like this:

<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
jQuery.noConflict();
jQuery(document).ready(function() {

});
</script>

Note - you might want to save this somewhere - it'll come in handy if you're doing a lot of this type of thing. Ok, once I had this in place, I used the following JS to select the checkbox:

jQuery("#checkbox input[type=checkbox]:eq(1)").attr('checked','checked');

Let's take a look at that particular call:

"#checkbox input[type=checkbox]:eq(1)"

This takes the checkbox div we created, and finds every input with a type attribute of checkbox. This actually returns 5 objects in my test report - an empty/hidden input, and 4 static choices I created. To select the first one, I just point to the [1] position using :eq(1). I could use 2 for the second, 3 for the third, so on.

.attr('checked','checked');

This is jQuery's way of saying "check this box!" All of that in one line. If you need clarification, please let me know.

(Full code)

<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
jQuery.noConflict();
jQuery(document).ready(function() {
jQuery("#checkbox input[type=checkbox]:eq(1)").attr('checked','checked');
});
</script>

melee

Quote from: MFGF on 12 Jan 2011 12:20:00 PM
I can't even spell SJ! :D

Sorry - I do try very hard to avoid javascript - it's my secondary goal in life.

MF.

Haha, I was the same way. jQuery really changed my mind.

Lynn

QuoteSorry - I do try very hard to avoid javascript - it's my secondary goal in life.

Dare I ask what the primary goal might be?

dtopicMedV

Quote from: Arsenal on 12 Jan 2011 11:28:42 AM
I wish I could help you but my JS skills are very limited  :-\

Thinking about it, would it help your situation to have static choice check box prompts? You won't need to use a JS then and since there are no prompt pages it's certain that the users can't make a choice in the prompt till the report actually loads. So, you could have a default choice within your static choice box so it runs for that default choice and then your users can make their choice and re run. You could also spoof an All option so the report initially runs for everything and then the users can pick their choice. Of course, if you have like 40 options to select in the prompt or values that change periodically then static choice would be too tedious to make.
Product Group prompt is data related and can't be hard-coded into a static list.
Different clients have separate db-s and different product groups.

MFGF

Quote from: Lynn on 12 Jan 2011 12:54:41 PM
Dare I ask what the primary goal might be?

Ah - a bite! :)  Ok - if you really want to know...  One day, I want to marry a handsome prince and live in a fairy castle. :D

Oh, sorry, I forgot.  That was last year's goal.  My new one (Mrs F says) is to lose a few pounds and do more housework <sigh> :)
Meep!

Lynn

QuoteMy new one (Mrs F says) is to lose a few pounds and do more housework

Below is the JavaScript you need for your primary goals (assuming you are willing to sacrafice the secondary goal)

;D


<script language="javascript">
var f = git_Yo_Arse_Outta_Bed_Early();
var list = f._EveryDayOfTheWeek;
var Counter = 0;
var ii;
for ( ii = 0; ii < list.length; ii++)
{
    var node = PickTreadMillBikeOrElliptical();
    case when (node.selected=TreadMill) {Run_A_Long_Time}
         when (node.selected=Bike) {Pedal_Fast}
         when (node.selected=Elliptical) {Pump_Arms_and_Legs_A_Lot}
         else {DO_NOT_GO_BACK_TO_BED}
    end
{ Counter++; }
}
</script>



<script language="javascript">
var f = Hire_A_Cleaning_Service();
var list = f._EveryDayOfTheWeek;
var Counter = 0;
var ii;
for ( ii = 0; ii < list.length; ii++)
{
    if (f.DayOfWeek = 2 or 5) {CleaningServiceDoesTheHeavyCleaning};

    var BrowniePoints = DontLeaveYourSocksOnTheFloor();
    var MoreBrowniePoints = UnloadTheDishwasher();
    var UltraBrowniePoints = DoTheLaundryIncludingFoldingAndPuttingAway();

    BrowniePoints.Complete=true;
    MoreBrowniePoints.Complete=true;
    UltraBrowniePoints.Complete=true;
{ Counter++; }
}
</script>

MFGF

Lynn, you have just converted me from a JavaScript bigot to a true believer. I never realised it could make my life so easy!

I am deeply in awe of your skills:D

(it was very amusing too - Made my day :) )
Meep!

melee

Quote from: Lynn on 13 Jan 2011 07:13:47 AM
Below is the JavaScript you need for your primary goals (assuming you are willing to sacrafice the secondary goal)

;D

hahaha, this is awesome!

Arsenal

LOL Lynn, that JS was absolutely awesome. Great for a few laughs  ;D

MF, you now need to come up with one that you or any man would expect from their wives/girlfriends. I have a feeling that the JS is likely to be VERY short ..maybe 4 or 5 lines of code?  ;D

MFGF

Ah.  Unfortunately, if I posted that, I'd have to ban myself! :)
Meep!

mohsin2010

HI MFGF,Lynn,Arsenal,Melee,

  Humm... . i am hearing your Conversation you all are very professional you people have very command on Cognos and many other tools .. . dont you see many coils and new bee like me needs help of your's to get out of problem then why dont you help us ?  ;)
     its not for MFGF he is a very good guy :)

Regards,

Syed Mohsin Raza

MFGF

Quote from: mohsin2010 on 14 Jan 2011 04:35:44 AM
HI MFGF,Lynn,Arsenal,Melee,

  Humm... . i am hearing your Conversation you all are very professional you people have very command on Cognos and many other tools .. . dont you see many coils and new bee like me needs help of your's to get out of problem then why dont you help us ?  ;)
     its not for MFGF he is a very good guy :)

Regards,

Syed Mohsin Raza

You must bear in mind that members on here are unpaid for the content they post on Cognoise, and often have very busy and demanding jobs.  People post answers simply because they a) wish to help others who are having problems, and b) because they know the answers or solutions themselves.  Given this, it's really unfair to name specific posters and demand to know why they haven't replied to your posts - they may not have the time, or they simply may not know what the answer is.  One thing I am fairly confident of, though, is that demanding answers from others will often dissuade them from replying, even if they do know the answer.  People who contribute freely do not generally like to be treated as a helpdesk and scolded whan they do not or cannot post answers.

MF.

PS - MFGF a good guy?  Not even close - he's a complete muppet! :)
Meep!

mohsin2010


MF,
      i post here to get information and those hurdles that i face but i posted this post after reading the posts of this thread i was feeling the environment just cool and like that of friendly conversation so i did that post just to be the part of good conversation with the professional once .. .
     
       my intend was not that as you posted previously that i was giving threat ??? but i think perhaps Professionals are Professionals we don't have any right to do conversation with them !
        Next time i will be aware n should mind my own buisness

   But i like to thank those who have been helping me ...

Best Regards,

Syed Mohsin Raza

MFGF

Apologies if I misunderstood your intent.  Friendly conversation is always welcome! :)  I'd like to think that even a totally new member with zero post count would feel welcome to join in with the friendly banter.  There are certainly a lot of professionals on here, but to set the balance straight there are also people who would class themselves as muppets too :D  You most certainly DO have the right to join in conversation with anyone you choose - as long as the content is not inappropriate of course :)

I don't agree with minding your own business - I find it far more entertaining to stick my nose in wherever I can! :D

MF.
Meep!

mohsin2010

MF ,

     dnt Apologise bro ... . MF Rocks... :D

    and now there is one more Muppet added to this Cognoise community and that is ME ....  :D ;D

Thanks alot ,

Syed Mohsin Raza.

MFGF

Meep!

melee

Quote from: mohsin2010 on 14 Jan 2011 04:35:44 AM
HI MFGF,Lynn,Arsenal,Melee,

  Humm... . i am hearing your Conversation you all are very professional you people have very command on Cognos and many other tools .. . dont you see many coils and new bee like me needs help of your's to get out of problem then why dont you help us ?  ;)
     its not for MFGF he is a very good guy :)

Regards,

Syed Mohsin Raza

Me? Professional?   :D

MFGF

Meep!

mohsin2010

HI  Muppet  :),

  how are you i m not using Cognoise now days due to my Examinations i will right back soon Take Care ;D 

Bst Regards,
Mohsin