Question

My query returns location_cd(string) and item_count(int). I only need certain rows from the result however and I need them to display in specific places in my layout so I don't think the table solution is going to work. Can I determine where I place the value for a particular row of the result set?

I am using a grid to display values for a number of fields. I cannot seem to be able to get the values from the results to show. The grid is bound to the result set. I even tried binding the cells to the result set but that didn't work either.

I checked in the query editor and there is a result set shown in the Preview so I know the query works. The complete and correct result set shows if I put a table on the page.

I tried inserting a Dynamic Text or Data object in a cell and used the expression:

dataSetRow["location_cd"]=="3SD"?dataSetRow["item_count"]:""

This returns a blank and does not seem to evaluate. I tested it with :

dataSetRow["location_cd"]=="3SD"?dataSetRow["item_count"]:"BLANK"

and got 'BLANK' to appear in that cell.

dataSetRow["location_cd"] and dataSetRow["item_count"] will display the location_cd and item_count from the first row of the result set. row.outer[] did the same thing. Obviously I am just hacking at this report at this point.

A co-worker suggested that she uses a JAVA if-statement in places like this but I could not get that to work either.

Any ideas or suggestions that will get me on the right road??

Thanks

Was it helpful?

Solution

An elegant option would be to use a HashMap storing the result of the dataset.

  • Declare a report variable named "values", with a new hashmap as default value (see image below)
  • Fill values in the onFetch script of the dataset: vars["values"].put(row["location_cd"],row["item_count"]);
  • Insert new data elements at any place of the report with expressions such: vars["values"].get("myFavoriteLocationCD");

Though it is important to note the dataset should be triggered by the report before these data elements.

enter image description here

OTHER TIPS

The particular row you want to display you specify in a "Text" field inside your grid. Just drag and drop a "Text" field inside your grid. If you bound the fields you want to display to your grid, the "Text" field inside the grid inherits the bindings of its parent (the grid), so you can access the bindings automatically in the "Text" field.

You could try following steps, maybe that works.

  1. Don't use "Dynamic Text" field, instead use a regular "Text" field
  2. Ensure the fields of your query which you use, are bound to the grid (you sayed you already did)
  3. Open the "Text" field
  4. Change preselected pull-down entry "Auto" into "HTML"
  5. Change preselected pull-down entry "Formatting" into "Dynamic Text"
  6. Wrap your code in <value-of format="HTML"> your code goes here... </value-of>

Note: You should check in the "Expression Builder" of your "Text" field if you are able to access the fields you bound to the grid. If they are not available sth. went wrong with your binding. Avoid binding query records to cells this will drive you crazy.

If you want to display a list, ensure you didn't set a constant height in the row of your grid. Set the height to 100% than the row takes its height dynamically.

What about the idea to optimize your query, that only get the results you want are displayed, than you don’t need to filter them with java script? If you don’t need the filtered results in another place this would be the cleaner solution in my opinion.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top