Please note that g_form.setVariablesReadOnly() method is undocumented and therefore not officially supported method. It is best practice to make field/variable read only using Catalog UI Policy.