Stora tag History as Gateway event

Hi all,

I feel like I am missing a small thing here.
I’ve created a script for storing tag history in a database by using system.tag.storeTagHistory()
In the first stage I’ve triggered the script directly to a button. So when I clicked the button, the script would run. This all worked fine.
Now it seems more profitable for me to call this script as a gateway script. So I’ve copied the script and pasted it in the Gateway events and on Tag Change.
The script triggers, but I get a lot of errors while running this script. All have to do with the Historical datasink that doesn’t exist. Which is strange, since it worked when it was connected to the button.
I took a look at the Logs of the gateway and got following error:
java.lang.IllegalArgumentException: Specified historical sink ‘Database 2’ does not exist
(and some stuff after this)

Which seems ok to me since I don’t use Database 2 anymore. I use following function:

So if there would be an error, I would expect it to happen it on “NewDatabase” and not on “Database 2”.
Is there a Gateway parameter which I need to adjust to get this to work?

Thanks in advance!