1
0
-1

Hi,

I am reading this Report Builder and having a hard time figuring out how to solve my use case. Here is an example of my problem. Let's assume there is a table that contains the following


IDfruitpricetext
1banana1.5Today the price of <fruit> is $<price>
2apple3.75The price of <fruit> has gone up to $<price>
3mango4.25<fruit> is the best fruit
4litchi5<fruit> at $<price> is too expensive

I need to create a report using report builder that will contain a sentence that will change depending on the selected row.

If row 1 then the text in the report will be "Today the price of banana is $1.5"

If row 2 then the text in the report will be "The price of apple has gone up to $3.75"

etc.

My prerequisites are :

  • I do not want to keep an extra column in the table with the computed text
  • I do not want to pass parameters 

This is just an example. In my real use case the texts will be several paragraphs and there may be more that 30 variables.


I need the variables to be replaced at run-time when the report is generated. Using hash variables I can show fruits, prices and texts independently, but I do not know how to combine them and do the replacements.


What is the best way to achieve this?




    CommentAdd your comment...

    2 answers

    1.  
      1
      0
      -1

      It seems that you will need a some sort of "rules engine sentence composer" somewhere to "think" and compose the sentences.

      will contain a sentence that will change depending on the selected row.
      
      If row 1 then the text in the report will be "Today the price of banana is $1.5"
      
      If row 2 then the text in the report will be "The price of apple has gone up to $3.75"

      A simple way is to write bean shell hash variable with IF-ELSEIF statements.

      For example, imagine we have such pseudo function.

      composeSentence( dateToday, priceYesterday, priceToday, itemName){
      
      	result = itemName;
      
      	if(priceToday > priceYesterday){
      		result += " is more expensive than yesterday by " + (priceToday - priceYesterday)
      	}else{
      		result += " is cheaper than yesterday"
      	}
      
      	return result;
      }

      Once you have build up this, then in your report builder, you simply iterate through and keep calling the beanshell hash I suppose.

      Hope this helps.

        CommentAdd your comment...
      1.  
        1
        0
        -1

        I don't think a stored record containing hash variables can be parsed.

        What I could think of as a workaround is using a Form Element in the Report Builder.

        Within the form, separate it by section. Each section contains the text/paragraph in Custom HTML. Use the section visibility to control which text/paragraph to display. The custom HTML would contain the text/paragraph as well as the 30 hash variables.

        This requires you to pass parameters though...sorry

          CommentAdd your comment...