I have a Text Field which gets populated with random numbers every time the form is opened.
the previous script contains a typo and won't work.
Try this script instead.
this.access = this.isNull ? "open" : "protected";
Add the following script on the initialize event of the textfield that should get locked.
if(this.rawValue != nul)
this.access = "protected";
I'm sure you could modify this for your purposes, but here's my solution with a checkbox instead of a button.
So, if that box is checked when the form is saved, the text field will not generate a random number when the form is opened again.