Could you share exactly what the script looked like when you had issues? I tried the syntax as it was originally and it worked for me, see attached picture. Note my gateway name and historian names are used in the function