Evaluate a field value in another field

Hello

Lets say that I have two fields, $F{INTRODUCTION} which value is "Ny name is $F{NAME}, and I am from Germany" and F${NAME} which value is "Franz Beckenbauer".

Is it possible for Jasper Reports to evaluate the NAME field in the INTRODUCTIONS field, so that it says "My name is Franz Beckenbauer, and I am from Germany"?

kry_1's picture
13
Joined: Sep 20 2022 - 2:21am
Last seen: 1 month 2 weeks ago

Thank you for posting to the Jaspersoft Community. Our team of experts has read your question and we are working to get you an answer as quickly as we can. If you have a Jaspersoft Professional Subscription plan, please visit https://support.tibco.com/s/ for direct access to our technical support teams offering guaranteed response times.

arai_4 - 2 months 1 day ago

Any news on this? :)

kry_1 - 2 months 15 hours ago

Thanks for the answer, @JRS-SE.

Yeah, I know that I can concatenate two fields together. My problem is that the data is defined in sql, so one cell called field_1 might have the content: "My name is $F{reference_to_another_cell_that's_written_in_plaintext}, and I am from Germany", so I can't concatenate the fields together, because it's hard coded in the actual data.

 

We're migrating from another report generator, where it was possible to create references like <<this>> and the generator would read the tag and replace it with value from what the tag was referencing. I'm trying to find if it's possible to somehow keep that functionality in Jasper Reports. I know that I can create some convoluted find a replace string mechanics when defining the text fields, or I can create a scriplet that can handle that functionality. I wondered if that kind of functionality was already in place.

kry_1 - 1 month 4 weeks ago
show 2 more...

Have you looked into the string functions in the expression editor? Does this help?

$F{Title}.replace( char, char )
$F{Title}.replaceFirst( String, String )
$F{Title}.replace( CharSequence, CharSequence )
$F{Title}.replaceFirst( String, String )
$F{Title}.split( String )
$F{Title}.substring( int, int )

JRS-SE - 1 month 2 weeks ago

Hi JRS-SE

Yes, I looked first a the string functions but I thought that there might have a more neat way to do that. My solution was to use a Scriptlet that uses some string replace methods, and calling that Scriptlet in the field. Then the field won't be filled with hard to read function calls.

Thanks for the guidance. :)

kry_1 - 1 month 2 weeks ago

3 Answers:

You can define your text-filed expressions in the following format: "My name is "+ $F{NAME}+", and I am from Germany"

JRS-SE's picture
5437
Joined: Oct 30 2017 - 12:56pm
Last seen: 2 days 10 hours ago

I found out that this isn't possible. The closest thing I got to this was by creating a Scriptlet that takes a parameter, and uses that parameter to replace parts of the string, and then returns the new string.

kry_1's picture
13
Joined: Sep 20 2022 - 2:21am
Last seen: 1 month 2 weeks ago

JasperReports engine (JRL) is a Java application, not a scripting application, therefore you cannot use string substitution directly in the text string.

What you can do, however is to use Java string substitution class method to achieve your goal:

$F{INTRODUCTION}.replace("$F{NAME}", $F{NAME})

tchen's picture
121581
Joined: Feb 27 2008 - 7:33am
Last seen: 1 day 18 hours ago
Feedback
randomness