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

Studio Expression Editor


graham.smith

Recommended Posts

Hi all - I'm new to using Jaspersoft, and am having some trouble understanding the operation of the Expresion Editor in Studio 6.6 - especially for expressions with multiple parts - such as an 'If - Else'.

 

The editor brings up three boxes for the three parts (condition - action if true - action if false), and it seems to be stable as long as each of the three has correct syntax.  However being new, I am still coming to terms with how to use the interface, and find that when I get one of the boxes wrong - I end up losing the whole statement and have to start again.  I got so frustrated with it last night, that I resoted to hacking the XML code instead of using the Expression Editor.

 

Is there a good 'in-dpeth' resource to help familiarise me with this tool, that explains its use with more complex expressions, and combining expressions, etc?  As an example - one of the tasks I am trying to do is pull the first name out of a user name field, where that field may have just one name, or multiple names separated by a space.  So I have a Variable called 'FirstName' configured with the expression...

 

IF($F{NAMES}.indexOf(" ") == -1, $F{NAMES}, $F{NAMES}.substring(0,$F{NAMES}.indexOf(" ")))

The last element of this expression is causing me problems (any help with that would be greatly appreciated), but each time I try something new in that element via the Expression Editor - I end up losing the rest of the expression and just my new trial code being left in its place.  I am sure it is simply down to my understanding of the product and lack of experience - but it is sure getting frustrating.  Any advice would be greatly appreciated.

 

Thanks in advance

 

Graham

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

I've been looking into the substring expression a little more.

By substituting actual numbers rather than the result of a function, I find that I can do .susbtring(0,1) and get the first letter... great. I can also go to substring(0,2) or substring(0,3) and get either the first two or three characters. HOWEVER, when I go to substring(0,4) - that's when it all falls apart and the report keeps failing. Now - I have noticed that the shortest name in the list is 'Max' which is 3 characters - is this coincidental, or significant? As that record is just a single name, then in theory, it should not be processed by the second action in the statement - unless the actions are validated against ALL records?

Link to comment
Share on other sites

SOLVED - it appears that it WAS the minimum length record that was causing the substring to fail, even though it was in a part of the IF statement that ensured it would not be executed. I confirmed this by amending the SQL Select to only pick out records where the NAMES field was longer than 5 characters, and was then able to get substring(0,5) to work as well.

The solution was to change the select statement to cast the NAMES field as char(25), to make sure that the field was always longer than the longest name, rather than being potentially shorter on the records that have short names.

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