Ask Your Question
1

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

asked 2019-01-30 14:12:07 -0600

iamontheinet gravatar image

I am using JavaScript 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:13:49 -0600

iamontheinet gravatar image

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

for(var i = 0; i < records.length; i++) {
  try {
    // Access each record field and its value    
    var record_dictionary = records[i].value;
    for (var field in record_dictionary)  {
      var field_value = record_dictionary[field];
      log.info("=== field: {} | value: {}",field,field_value);

      // do something... 
    }

    // Write record to processor output
    output.write(records[i]);
  } catch (e) {
    // Send record to error
    error.write(records[i], e);
  }
}

Cheers, Dash

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-01-30 14:12:07 -0600

Seen: 3 times

Last updated: Jan 30