This suggests that you are not using the script in a listener.
As you can see in this example, the code you have is perfectly valid when used in the context of a listener - https://library.adaptavist.com/entity/update-the-value-of-a-custom-field-using-a-listener
Note - the way scripts have a context makes it hard to write and test them if you put them in the wrong context. For example, if you're writing a listener, you need to put the code into a listener, you can't develop in the script console because the console will not have the "event that was caught" in the context. Similarly for conditions, post-functions and validators - the console does not have "issue the transition is running against" in the context.
Hello Community! Quick disclaimer: We are running a contest on Community (The Atlympics!) from July 23rd - August 8th of 2021. If you are interested in participating in this contest (prizes! ...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events