I'm getting this warning (see screenshot) even though my script works perfectly fine.
I've read through the forums as many people have posted this error but no answers seem to make any sense. Anyone have any practical advice to fix this error for scripts stored like this one?
I'm guessing I have some kind of syntactical error but trying to modify my script to look like others here isn't working.
This script is used for a script field.
I think this is somewhat expected.
This script doesn't exist in a vacuum. If you tried to run in the console it would not work because it assumes a certain binding for the context that it will be run in to exist.
For example, if this is a post-function script, when you go to the configuration where that file is called, the static type checking should report green (no errors) because in that context, the issue variable will be declared and the static type checking known that.
In the Script Editor, the static type checking doesn't know where you intend to use that script and what bindings will be available.
Adding Issue issue= issue in a script is really just a hack/trick to hide ALL OTHER static type checking you would otherwise see in the script editor.
You have to accept this error and move on. Any workaround to get rid of the errors will bring more headache or code complexity than they're worth.
For the record, this should work (I've never actually tried to use this in prod):
//You want to use a different variable than 'issue', otherwise you may get an error that 'issue is already declared'
//and obviously, all subsequent calles to issue should be replaced with new variable name
Issue myIssue = this.binding.variables['issue']
You can read more about Static Type checking here: https://docs.adaptavist.com/sr4js/6.30.2/best-practices/write-code/static-type-checking
My recommendation is to ignore the error. If that's the only one you see in your script, it's in better shape than the majority of my scripts in my environment (>180 scripts).
You see that errors in the Script editor ... but I suspect if you were to put the exact same code n the Script Field in-line script box, you would see this different error instead:
To avoid that error in in-line script, you could remove the line altogether or set it to this:
But this would show the same error in the script editor since script editor doesn't know about "issue".
In the script, "this" can be used to access the class that contains the script, and one of the built-in properties of a script class is its binding which contains the variables defined prior to calling the script.
There is not a single line that you can replace your line 14 that will just work any of the lines I suggest will result in either an error in the Script File Config (context-aware) or in the Script Editor (not context-aware).
The only solution is to NOT attempt to re-use the existing "issue" variable and instead declare a new variable with a different name and loading it with the "this.binding.variables['issue']"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes thank you Peter. It's the only warning and the script runs fine so I've learned to live with it. It's interesting to learn how the STC works different in the editor versus console versus in-line script. Thanks for the thorough explanation.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You're welcome.
Might I suggest you change the accepted answer to the answer I provided instead of your reply that was posted as a new response?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for the response Peter. I think I'm following what you are saying.
To try your code out in our UAT environment would I literally write this?
Issue myIssue = this.binding.variables['issue']
aka I would replace my line with the above line as is?
I'm not sure what you mean 'this.binding.variables['issue'] part. I don't understand if I'm supposed to put something else there other than what you literally wrote.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Perhaps easier said is, if you were to look at my screenshot and were to replace line 14. how exactly would you replace that line?
Ideally something I could copy and paste exactly.
The code is for a script field which has its context set for various issue types and different projects.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.