Hitachi Vantara Pentaho Community Forums
Results 1 to 3 of 3

Thread: Trying to use "if" statement in User Defined Java Expression step

  1. #1
    Join Date
    Apr 2012
    Posts
    12

    Default Trying to use "if" statement in User Defined Java Expression step

    Hi,

    I'm a newbie to both Pentaho Data Integration and Java, but trying to dive in with both feet. I'm trying to process an xlsx file and in one of the fields, the last character may or may not be a "/". If there is a "/", I need to delete it. I tried the following java "if" statement inside the User Defined Java Expression step:

    if(FIELD.charAt(FIELD.length() - 1) == "/"){FIELD.deleteCharAt(FIELD.length() - 1)}

    I got the following error: Line1, Column 1: Unexpected token "if" in primary

    How does one use an "if" within a User Defined Java Expression step?

  2. #2
    Join Date
    Dec 2010
    Posts
    304

    Default

    Hi jhuhtala, use

    FIELD.charAt(FIELD.length() - 1) == '/' ? FIELD.substring(0, FIELD.length() - 1) : FIELD

  3. #3
    Join Date
    Apr 2012
    Posts
    12

    Default

    Thanks, that did the trick!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.