Neither script does what you think that it does.
In both cases, the scripts copy a value to a variable and change layouts. Neither does anything with that variable once setting it to a value.
The fact that one appears to work and the other doesn't is simply a case of the correct record happening to be the current record on the layout specified in the first script while the second, from your description, either has a blank record as the current record or it has no records at all in the current found set--either would produce the empty fields expected for a "new record".
To change layouts and pull up a specific record can be made to work in three ways:
- Both the original layout and the one that your script is changing to are based on the same Table Occurrence. Two layouts based on the same table occurrence in the same window will share the same found set, sort order and current record.
- You use a scripted find to find the needed record on the new layout. This can be where copying a value to a variable might be used as you might then use that variable to set up find criteria for a find on the new layout.
- Go To related records can use the current record on the first layout and a defined relationship to pull up one or a group of related records on the second layout all in one script step.