Jump to content
We've recently updated our Privacy Statement, available here ×

Evaluate a field value in another field


kry_1
Go to solution Solved by Tirupathi Mangalarapu,

Recommended Posts

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"?

Link to comment
Share on other sites

  • Replies 8
  • Created
  • Last Reply

Top Posters In This Topic

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.

Link to comment
Share on other sites

  • 2 weeks later...

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. :)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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})

untitled_0.thumb.png.52c8eaff6716abc810530a9275863c13.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...