You are on page 1of 46

1

2
3
4
5
6
Sample prompt page layout. There are three HTML items.
The first item is used to open a div tag, the second item closes the tag and holds the function script code,
finally, the third item is used to replace the Finish button.

7
8
9
10
1. This section actually creates the button on the page. The button is named FinishButton2 so that we
can call it. The only action attached is onclick it will call the CountSelected() script created instead of
doing the normal finish button action.
2. This section scripts the button so that it will behave just like a normal Cognos Finish button. If we didn’t
add this, the button wouldn’t have the enable/disable functionality tied to required prompts. Adding this,
the prompt will only be enabled when all required prompts have been answered, just like using the
normal Finish button.
3. To use this finish button function, we need to call the prompt button object. However, the prefix value
oCV… is different depending on how the report is called, it uses a different prefix for Report Studio,
Interactive Cognos Viewer, and Batch Cognos Prompts, so we need to call the object to know what
prefix to use.
4. This final section ties this functionality to the new Finish Button created above.

11
The user comes to the prompt page, sees the prompt and just automatically selects Select All to quickly
move on to the report. However, when they click on Finish, the report does not run, and instead they get
an alert telling them they selected too many values and they must only select 10 items or less. They go
back to the prompt, deselect everything, and only pick a handful of items this time. On clicking finish the
report now runs as expected. The user could keep hitting Finish all they want, but the report will not run
until they satisfy the condition we defined.

12
1. Open the script and declare it as javascript.
2. Create the function, CountSelected()
3. Grab the prompt object we surrounded with the DIV tag.
4. Grab the input part of the object that will store the user selections.
5. Here we will count how many of the items the user has checked.
6. We now test this value, we are using less than 11 so that the user must only pick up to 10, this where
we could easily change how many objects a user can select.
7. If the test is true, then the Finish action will be run, the same as clicking on the Finish button normally.
8. If the test didn’t pass, the alert will pop up, and the Finish action will not be called, and can’t be forced,
until the user limits their selection.

13
Here, a user has a picklist box in which they can select any number of objects. They do a drag click on a
bunch of objects and click finish. The alert comes up saying they selected 22 items and they must select
10 or less. They go back to the prompt, and select a correct number of items, then click on Finish.

14
Same basic script as the checkbox previously, with one major change. Since this is a different prompt, the
tag name is different
1. In this case, once we grabbed the prompt object, we find the select tag, this one holds the prompt
items, we then count the items in this array that have been selected.

15
Here is a Search and Select Prompt. A user enters the wildcard value of % and gets every possible
member in the Results box. The user then does a drag select and adds a bunch of those elements to the
choices box. However, when they click on finish, they are greeted with our now familiar alert box saying
they have too many items selected. They go back, remove a lot of choices, leaving a correct number, click
on Finish and the report runs.

16
1. This prompt is slightly different, no need to count the items, the OPTION element is an array of the
records added to the selection box.
2. We check the length of values in this array and that gives us directly the count of items the user has
selected and this value can now be tested.

17
This example has two different prompts, but they are each still limited to a selection of 10 or less. The user
selects all in both prompts, but when the click on Finish, an alert box pops up to tell them they have more
than 10 items selected in the checkbox prompt. They click OK, and another alert pops up to let them know
that they have more than 10 items selected in the picklist prompt. They click OK and the final alert pops up
informing the user that they need to fix the prompts first and then click on Finish again.
They fix the picklist prompt, click on finish, but the checkbox prompt still fails, and they are informed to fix
the prompts again. This time they fix the checkbox prompt as well, click on finish and the report runs.

18
Here is the prompt page for the Multiple Prompts. As before, the prompts are surrounded with HTML
Elements, however, there is also a new one.
The first element creates the div tag, the second element closes it and has the script to check this prompt.
The third element creates another div tag with a different name, and the fourth element closes this div and
has the script to check this prompt.
The new, fifth element, has the script to get the return counters from the individual prompt scripts and
determine if the prompts are good or not.
The sixth element is our standard finish button.

19
1. A descriptive name for the functions around each prompt to be checked.
2. Don’t check the value, just pass the value in a return.

20
1. A new function and a new descriptive name
2. Find and count the selected elements
3. Pass this value to the calling function

21
1. This function will check that all the prompts are good and then call the prompt action finish correctly.
This is the function name to be called in the Finish button.
2. These variables set how many selections are good in the prompts, and how many prompts to be
checked. We are only using two for demo purposes, but can set as many as needed for the prompt
page.
3. This prompt will hold the number of good prompts.
4. Call the first prompt function and get back the number of checked values.
5. Call the second prompt function and get back the number of selected values.
6. This checks to see if the first prompt is limited correctly.
7. This checks to see if the second prompt is limited correctly.
8. This checks how many prompts are good, and finishes if they match the number of prompts, else it
asks the user to fix the prompts.

22
23
In this example we have two prompts, one of them MUST be answered. Try to click finish and the alert
pops up, answer one of the prompts, the report runs, can even answer both prompts, and the report shows
up, the only limit is that at least one of the prompts is answered.

24
Like the other Multiple prompts page, each prompt is surrounded with HTML elements, the left tag creates
the div tag, the right one closes the tag and runs the script to check how many items are selected. The
fifth element will then check to make sure all the constraints are met on this prompt page, and finally the
last element will create the Finish button.

25
The script looks the same, finding the element with the selection and counting how many elements are
checked, then returning it back in Counter.

26
Again, this script looks the same as before, counting the objects and returning the count in Counter2.

27
1. The prompts used before to define the number of prompts to check, and the limit values for those
prompts.
2. This new variable sets how many prompts are allowed to be answered, can be set to a value of 1 if you
only want 1 prompt, up to the number of prompts on the page.
3. This new variable determines how many prompts MUST be answered. Can be set to 1 or more to
require some prompts be answered, can be set to 0 to allow no prompts be answered.
4. These call the check prompts to determine how many selections were made.
5. These will check to see if the user answered too many prompts and set the good prompt counter.

28
1. These will check the prompt counters to determine if the prompts were answered. It will update the
answered prompts counter for each prompt that was answered.
2. This will check to see if the answered prompts is larger than the number of answered prompts, if they
answered too many, it will alert the user, else it will update the good prompt counter.
3. This will check to see if they answered enough prompts. If they didn’t answer enough, it will alert the
user and check the good prompt counter.
4. This will check to make sure the prompts were all answered correctly. It uses the number of prompts
value, and adds two for the max and min answered prompt conditions.

29
In this example, there are two prompts, only one prompt is allowed, also, the prompts themselves are
limited to only 10 selections. I pick values in both prompts, click finish and the error pops up. I then lose
one, but go ahead and pick all the selections in the first one, and again it errors out. I only pick a couple in
the first prompt, and it runs. I try it again, this time I don’t pick any values, and again it runs, this is
because I only set it to allow a maximum, but not a minimum.

30
Here is a truncated version of the same script used in the Multiple Prompts One is Required. The script is
the same, we only adjust the variable values.
1. Here we set that only 1 prompt can be answered.
2. Here we say that there are 0 prompts required.

31
32
This example shows auto cascading prompts. There is a country filter, and then a radio filter. The user
can select countries, up to three, and then either choose the Retailers in that Country to pick from, or the
Sales Branches. This list of Retailers or Sales Branches will change as the user adds/removes countries.
I search all countries, then I choose retailers, and the retailers prompt shows up, but empty. I double-click
on a country, and the prompt is populated. I then click on a country and click on Insert, the prompt is
updated. I click on Sales Branches, cause I want to search by those instead, and the prompts is changed.
I add a couple more countries, and I get the alert that only 3 is allowed, I click on a country and click on
remove and the prompt is again automatically updated.

33
(video) This shows the prompt page, and the bounding prompts. For the search and select, it looks
normal, the div tag and the script to check the values. The radio box is slightly different, all that is
happening is to bound the object in the div tag. Finally, the finish button script looks normal, but there is
another prompt box next to the finish button that is new.

34
(video) Here we see some of the differences, the two prompts in the same table cell have render variables.
The different prompts will render depending on what is picked in the Radio Box. Finally, this new HTML
item has some different script code, this handles telling the page when to reprompt correctly.

35
This script sets up the conditions to watch on the page.
1. This new script is like the normal CountSelected(), it will test the number of countries selected
whenever the page is reprompted, but it will NOT call the finish action as the user probably isn’t done.
2. This function will call the CountSelection() and reprompt the page.
3. This function will add the onClick(testFunc()) to the radio button, reprompt whenever the radio button is
clicked to signify a different radio prompt.
4. This function will add the onClick(testFunc()) to the Insert button, reprompt whenever a item is inserted
into the selection list.
5. This function will add the onDblClick(testFunc()) to the results box, reprompt whenever a country is
added to the selection with a double click.
6. This function will add the onClick(testFunc()) to the Remove button, reprompt whenever a country is
Removed from the selection list.
7. This function will add the onDblClick(testFunc()) to the Selection box, reprompt whenever a country is
removed with a double click.

36
8. These calls will start these functions to watch the actions.

36
1. Check to see how many options are in the selected list, if less than 4, the condition is true.
2. If true, don’t finish, just return.

37
This is the function what will be called whenever an action is done on the page that we set to cause a
reprompt. It will first test the number of countries and alert the user if there are too many, but it will
continue the reprompt so the user can fix their issues. Then it will return to the calling function so the
action functions can continue.

38
This function tests the radio box.
1. Find the prompt itself with the div tag name
2. Find the different items in the prompt
3. Find the actual object that has the selection elements, in the radio box we use the class name to find
the actual node object.
4. When the element is clicked, run the testFunc()

39
This function looks the same, the big difference is how we find the node.
1. We don’t actually watch the selection box, instead we find the buttons, and then the Insert button and
watch when that is clicked. The insert button has a title Add selected items to your choices, so we find that
object and attach the onclick function.
2. The cuntion is slightly different, we wrap a setTimeout around it. I found that it takes a little bit of time for
Cognos to actually add the object to the selected list, so we want to make sure this is done before we call
the reprompt.

40
Again, the basic design of the function is the same, the two differences here is what node we want to
watch, and the type of watch.
1. In investigating this object, I found that inside the prompt object, and inside the div the node that users
double click on has no class name, so I reference it that way.
2. Since I want to see if they add a value by double click, that is what I am watching.

41
Here we find the buttons again, and this time we look for the Remove button and watch when that one is
clicked.

42
This time we are looking inside the select box, so we find the prompt, and the node items with select. Then
we search those nodes and look for the class list control and watch this box for a double click action.

43
44
45

You might also like