Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hi!

Replace your code with the following and it should work:

def upperCaseFirstLetter(fieldValue)    {
  StringBuilder ret = new StringBuilder(fieldValue.length());
  for (String word : fieldValue.split(" ")) {
    if (!word.isEmpty()) {
        ret.append(word.substring(0, 1).toUpperCase())
        ret.append(word.substring(1).toLowerCase())}
    if (!(ret.length()==fieldValue.length()))
        ret.append(" ")
  }
  return ret.toString()
}

for (record in records) {
  try {     

    //Uncomment to process ALL fields
    //for ( item in record.value ) {
    //  record.value[item.key] = upperCaseFirstLetter(record.value[item.key])
    //}

    //Process individual fields
    record.value['field1'] = upperCaseFirstLetter(record.value['field1'])
    record.value['field2'] = upperCaseFirstLetter(record.value['field2'])    

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

Cheers, Dash