I’m sure your users look at some common reports and tell themselves “This would be much easier if I didn’t actually have to select every single inane value on the report” – well, thanks to a very good question on COGNOISE, I’m going to show you a one line method to make one of these common prompts much more user-friendly (common theme on this blog!). Here’s the question from cognostechie:
Trivial question for most of you
I have a Value Prompt for selecting the Year. I want the default selection to be the current year. Is there a way to tell RS to determine the current year ? Wrap an HTML item around the Prompt? or sort it descending and set the focus to the first item? any other way?
Not trivial! A very good question indeed. Let’s get started.
I added a simple prompt that pulls years – that’s all for this example. I’ve also added the standard jQuery HTML item, but one thing I’m doing differently is addressing the prompt directly through its ID. This may be a naive move for me, because in the future, IBM could easily change the ID for select boxes. In that case, wrapping the prompt in DIVs would probably upgrade nicely. It is your choice.
So I ran the report and used Firebug to investigate what was going on. I used the “Inspect element” function to find out what the ID of the value prompt was:
There it is. PRMT_SV_N16AF5420x1A4180E0RS
Now that I know what the prompt ID is, I can transverse the DOM quickly to change the prompt. So, I fire up Firebug’s console and start firing some commands off. This is the one that changes the prompt to the current year:
It’s pretty simple – select the prompt, and change the value to the current date. One line of simple, sweet code.
Here’s what the final code in the HTML item looks like:
<link type="text/css" href="/cognos8/common/css/ui-lightness/jquery-ui-1.8.5.custom.css" rel="Stylesheet" />
}); // End Ready