Ask Your Question
1

How can I access each record field and its value in Groovy?

asked 2019-01-30 14:22:29 -0600

iamontheinet gravatar image

I am using Groovy Evaluator processor in my pipeline and I would like programmatic access to each record field and its values in a loop. How can I achieve that?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-01-30 14:24:17 -0600

iamontheinet gravatar image

You can use the following Groovy code to iterate through each record (field,value) pair:

for (record in records) {
  try {     
    // Access each record field and its value
    for ( record_dict in record.value ) {
      log.info("=== field: {} | value: {}",record_dict.key,record.value[record_dict.key])

      // do something...
    }
    output.write(record)
  } catch (e) {
    log.error(e.toString(), e)
    error.write(record, e.toString())
  }
}

Cheers, Dash

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-01-30 14:22:29 -0600

Seen: 6 times

Last updated: Jan 30