To set something on the global object, use Script.SetField using Script.Global as the instance object. Writing from memory, but do believe those are the API of interest.
You can update the script template if you want to add some directly authored JavaScript instead of generated script.