records = sdc.records
try {
if ((sdc.records.getAt(0).toString().contains("com.streamsets"))) {
deviceNames = []
int t2 =0;
for(record in records) {
connectedDevices = []
if (deviceNames.contains(record.value['networkDeviceId'])) {
} else{
t2 = deviceNames.size();
newRecord = sdc.createRecord(record.value['networkDeviceId'])
newRecord.value = ['connectedDevices' : 'val2']
newRecord.value = ['networkDeviceName' : 'val2']
deviceNames.add(record.value['networkDeviceId'])
newRecord.value = ['networkDeviceName' : record.value['networkDeviceId']]
connectedDevices.add(record.value['connectedDevices'])
newRecord.value['connectedDevices'] = connectedDevices
}
sdc.output.write(newRecord)
}
}
}catch(ed){}
Here in this script we are adding new "networkDeviceId" to the deviceNames[] array in the "else" part,so whenever we encounter a "networkDeviceId" which has already been there and has been feeded into the deviceNames[] we would end up in the if part of the script.
We are facing trouble with the "if" part of the loop,where we have to find the record created in the "else" part having the same "networkDeviceId" ,and we have to add the "connectedDevices" array to this particular record.
While creating the record we are adding
networkDeviceId to the header(using newRecord = sdc.createRecord(record.value['networkDeviceId']) ),so all the records would have the header value as networkDeviceId.