using a parameter to construct a field

Jaspersoft Community 'Read-Only' as of July 8, 2022

Transition to New TIBCO Community Just Weeks Away

You can still search, review wiki content, and review discussions in read-only mode. Please email community@tibco.com with questions or issues requiring TIBCO review or response.

Hi,

 

I have an excel file that contains a few columns with article descriptions like short_title_NL,short_title_EN, short_title_DE

I want to generate a report in the language that a user has chosen via a prompted parameter.

e.g. the user types in NL for the variable Language, and the chosen column to display in the report would be the description in dutch, so the field short_title_NL would have to be printed.

I've tried to create a text field like this:

$F{"short_title_" + P{Language}}  in the hope that it would evaluate to $F{short_title_NL}

But I get the error 'Field not found: "short_title_" + P{Language  --- net.sf.jasperreports.engine.design.JRDesignExpression

 

Can someone point me in the right direction? Please bear in mind  that this is an excel file.

Thanks,

Tom

tom_45's picture
43
Joined: Oct 14 2018 - 8:45am
Last seen: 1 year 3 weeks ago

2 Answers:

That won't work. You'll need to make it into 2 separate parameters and combine them in the sql clause to retrieve the data.

If the field is static, you may want to investigate on using resource bundle.

http://zetcode.com/articles/jasperresourcebundle/

 

hozawa's picture
131866
Joined: Apr 24 2010 - 4:31pm
Last seen: 3 years 3 weeks ago


Hi, 

Thanks I don't know if this would work with excel (can't use sql).

But I got the same result using this in the expression editor:

 

( $P{taal}.equals("NL") ? $F{short_title-nl_BE} + " " + ($F{baseline-nl_BE}!=null?$F{baseline-nl_BE}:"") :
( $P{taal}.equals("FR") ? $F{short_title-fr_FR} + " " + ($F{baseline-fr_FR}!=null?$F{baseline-fr_FR}:"") :
( $P{taal}.equals("DE") ? $F{short_title-de_DE} + " " + ($F{baseline-de_DE}!=null?$F{baseline-de_DE}:"") 
    : $F{short_title-en_US} + " " + ($F{baseline-en_US}!=null?$F{baseline-en_US}:"")
)))

tom_45's picture
43
Joined: Oct 14 2018 - 8:45am
Last seen: 1 year 3 weeks ago
Feedback
randomness