Thanks a lot @cjcenizal!
In was already familiar with that thread. After going over it again I found what I was looking for.
The script needs to go to the "Create Scripted Field" form, to the "Script" input
Then, in the Visualization, in the Advanced->Json Input one needs to specify {"script": {"lang":"groovy"}}.