AnsweredAssumed Answered

Parsing String in Map using Groovy returns Null

Question asked by 23217526 on Jun 10, 2016
Latest reply on Jun 10, 2016 by 23217526

Hello,

 

I need to extract the L, W and H from a string such as W=9.813 X H=11.5 X L=12.813 that will be received as column on a flat file and may be in any order, so I wrote the script below in Groovy which works on the Groovy Console, but returns NULL for all variables when I use it in a map:

 

def d = ' W=9.813 X H=11.5 X L=12.813'
def newarg = d.replaceAll(' ', '').replaceAll('X', ',').tokenize(',')

def L = 0
def H = 0
def W = 0
newarg.each {

   def arr = it.tokenize('=')

   switch( arr[0]) {

   case 'L':

  L = arr[1]

  println "L = " + arr [1]

   break
  case 'W':

  W = arr[1]

  println "W = " + arr [1]

   break
  case 'H':

  H = arr[1]

  println "H = " + arr [1]

   break
   }

}

println L

println H

println W

 

When I run it on the Console, I get:

 

\ParsingString.groovy

W = 9.813

H = 11.5

L = 12.813

12.813

11.5

9.813

 

But when I use it in Boomi like this:

 

def newarg = d.replaceAll(' ', '').replaceAll('X', ',').tokenize(',')

def L = 0
def H = 0
def W = 0
newarg.each {

   def arr = it.tokenize('=')

   switch( arr[0]) {

   case 'L':

  L = arr[1]

   break
  case 'W':

  W = arr[1]

   break
  case 'H':

  H = arr[1]

   break
   }

}

 

 

I get:

 

Function Execution: Scripting-  Output[9:L, null]

Function Execution: Scripting-  Output[11:H, null]

Function Execution: Scripting-  Output[11:H, null]

 

but there's no error.

 

Any help with this will be appreciated.

Outcomes