Expressions not defined

One Star

Expressions not defined

I am trying to use some of the build-in functions in the expression builder. Several functions give an error saying that the method is not defined:
An example of this is the LEFT function:
The method LEFT(String, int) is undefined for the type TalendJavaSourceViewer31

In the Expression Builder (in a tMap), I have:
LEFT(row1.FirstName,50)
One Star

Re: Expressions not defined

You need to refer to the function as
StringHandling.LEFT(row1.FirstName, 50)

LEFT is a static method defined in the StringHandling class.
Regards,
Abhi
One Star

Re: Expressions not defined

Ok. Tried that, and still getting an error. The syntax is now correct in the tMap expression, but when I run the full job I get:
Exception in component tMap_1
java.lang.NullPointerException
at routines.StringHandling.LEFT(StringHandling.java:209)


The code in my tMap expression is:
StringHandling.LEFT(row1.FirstName,50)
One Star

Re: Expressions not defined

I think you are getting "null" value for row1.FirstName. While making a call to StringHandling.LEFT, we need to ensure that row1.FirstName is not null. The following expression will evalute to null if row1.FirstName is null, else it will return the first 50 characters of row1.FirstName (or row1.FirstName itself, if length of row1.FirstName is less than 50).
row1.FirstName != null ? StringHandling.LEFT(row1.FirstName, 50) :
null
One Star

Re: Expressions not defined

That was the answer. Thanks!
Seven Stars

Re: Expressions not defined

All StringHandling methods will be null friendly in v4.0.4 and v4.1.2 (see here).