Normally records are processed one at a time. You only have access to values in the current input record and can ony write values for the current output record. You cannot write values to fields that have already been processed or set field values in records that have yet to be processed.
If you want to retain access to a field's value while processing a subsequent record your script would need to store the value in a variable or a list, as described above. If you wanted to output a stored/calculated value in a specific output record then you would need to use the node.execCount value as part of the 'if' test for outputing a record.
You can use the node.write() function to ouptut multiple records for a particular input record (the default text in the Transform node shows one example).
In the example below records are only output once all the input records have been processed (in this case none of the input data is actually used). A list of color values and an empty list are initialized in the ConfigureFields script. The Idx list has the execution count appended for each record (just as a proxy to indicate some 'work' being done for each record processed). Once all records have been processed the node outputs the multiple records comprising the values of the elements in the Idx list and the color values from the rainbow list.


Note that this is just an example of how to write multiple records for a particular input record (the last in this case - but you can do something similar for the first or the Nth). It is not intended to be a robust example as if there were less than seven input records it would have generated an index out of range error for the Idx list.