Question

Access fieldname and values in sdc.records in jython evaluator processor

  • 7 August 2023
  • 3 replies
  • 57 views

I’m trying to access each value inside a record using field name. But getting an error which says record has no attribute value.

What is the correct approach to access and modify values in each record in a loop?

PIPELINE-

ERROR - 

CODE - 

for record in sdc.records:
    try:
        sdc.output.write(record.value["name"])
    except Exception as e:
        sdc.error.write(record, str(e))

DATA SOURCE - dev raw data source 

{
    "id":1,
    "name": "anjay",
    "company_name":"persistent"
    }
    {
    "id":2,
    "name": "Binjay",
    "company_name":"persistnt"
    }
    {
    "id":3,
    "name": "Cinjay",
    "company_name":"infosys"
    }
    {
    "id":4,
    "name": "Dinjay",
    "company_name":"infsys"
    }
    {
    "id":5,
    "name": "Einnjay",
    "company_name":"cisco"
    }
    {
        "id":6,
        "name": "Finjay",
        "company_name":"sisco"
    }


3 replies

Userlevel 2
Badge

@nachiket_pethe please see the example code below which change the case to uppercase for each ‘name’ field

for record in sdc.records:
try:
record.value['name'] = record.value['name'].upper()
# Write record to processor output
sdc.output.write(record)

except Exception as e:
# Send record to error
sdc.error.write(record, str(e))

 

Thanks for the reply @Sanjeev.

I tried to run the exact same code but got the same error.

 

Userlevel 5
Badge +1

@nachiket_pethe 

There shouldn’t be any issues in the code suggested by sanjeev but try too import the attached pipeline and check if it helps.

Reply