I'm trying this:
import com.atlassian.jira.component.ComponentAccessor
def watcherManager = ComponentAccessor.getWatcherManager()
def userManager = ComponentAccessor.getUserManager()
def issue = event.getIssue()
def user = userManager.getUserByName("username")
if (cfValues['FIELD']*.value.contains("VALUE")) {
watcherManager.startWatching(user, issue)
}
And I'm getting this error:
groovy.lang.MissingPropertyException: No such property: event for class: Script51 at Script51.run(Script51.groovy:6)
Any idea what I'm doing wrong?
Hi,
If this is a post function then your code should be as follows. I'm going to assume that ID of your custom field is 11111 and its type is 'text (single line)'.
import com.atlassian.jira.component.ComponentAccessor
def userManager = ComponentAccessor.getUserManager()
def watcherManager = ComponentAccessor.getWatcherManager()
def cfManager = ComponentAccessor.getCustomFieldManager()
def cf = cfManager.getCustomFieldObject((Long) 11111)
def user = userManager.getUserByName("username")
if (issue.getCustomFiledValue(cf).equals("value")){
watcherManager.startWatching(user, issue)
}
Hi Ivan,
Thanks for your reply. My field is a select list (single choice). I guess this is why I'm getting this error?
Thanks,
Ovidiu.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah, I see. Then the code should be as follows:
import com.atlassian.jira.component.ComponentAccessor
def userManager = ComponentAccessor.getUserManager()
def watcherManager = ComponentAccessor.getWatcherManager()
def cfManager = ComponentAccessor.getCustomFieldManager()
def cf = cfManager.getCustomFieldObject((Long) 11111)
def user = userManager.getUserByName("username")
if (issue.getCustomFiledValue(cf).getValue().equals("value")){
watcherManager.startWatching(user, issue)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ivan,
I'm getting the exact same error with this syntax.
The cf is defined as you mentioned and it doesn't give any errors:
def cf = cfManager.getCustomFieldObject((Long) 11403)
Thanks,
Ovidiu.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There's a typo on line 10.
Instead of:
issue.getCustomFiledValue(cf).getValue().equals("value")
it should be:
issue.getCustomFieldValue(cf).getValue().equals("value")
After that you can pretty much ignore other static type checking errors. It should work.
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.
I assume you are trying this in a listener?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry, didn't mention this part. Doing it as a post function as part of the create transition.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.