There are multiple ways to do that.
Many of them would use a value in the field fo that record in one way or another to avoid setting data to a field more than once for a given record.
The value in the fields could be a number field set to 1 by the script. It could be an auto-entered creation or modification date field. It could be just a matter of check to see if data is alread present in this field.
It may also be possible to set up an auto-enter field option that automatically enters the needed data from a related record when the record is first created. That would not use any script at all.
That helped me with the logic!