What is your automation script on? Some script launch points (such as integration IBM Maximo Autoscripting Guide – Object structure scripting) you'll have a method where you pass in a parameter that you need to use instead. In the IBM documentation, the parameter is ctx so you'd use:
ctx.error() instead of service.error()
Also, if you're calling the script as a library script you'll need to pass in the service parameter to your library script.