For fields, you want to set read-only, below is the one solution you can follow.
- suffix your field name with ReadOnly and while traversing your nodes in the script, write the below script to check if your field name ends with ReadOnly then set that field to read-only and the rest of them will be...