You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
how can I Set watcher based on Custom field using scriptrunner :
Hey Taher!
That should be accomplishable using a script like this:
import com.atlassian.jira.component.ComponentAccessor import com.onresolve.jira.groovy.user.FieldBehaviours //Get appropriate managers def watcherManager = ComponentAccessor.getWatcherManager() def cfManager = ComponentAccessor.getCustomFieldManager() //Get your custom field def customField = cfManager.getCustomFieldObject().find{it.name == "Custom Field Name"} //Grab the application user that you'd like to add as a watcher from the custom field def userToWatch = issue.getCustomFieldValue(customField) //Set the user to watch the provided issue watcherManager.startWatching(userToWatch, issue)
This script assumes that the custom field that you are working with is a SINGLE username and that you are using this script in an application that already provides the issue as a preset value.
If you could provide me with some more specifics as to what exactly you are needing this for, I could supply you with a more specified script :)
Let me know if that works for you!
Aidan
Hi @Aidan Derossett _Adaptavist_, I'm trying to do a similar thing with our lira instance and scriptrunner. We have a custom field called 'Website' cf[11602] which is a checkbox selection with 3 choices. I'd like to add 2 users as watchers if one particular checkbox is selected. I've found a lot of old answers (pre jira 7), but none of them seem to work. This is the most recent post, and seems fairly close to what I want to do. Could you help me modify this to work for my purpose? Here's what I've been playing around with. I'm sure there are some imports the aren't necessary.
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.fields.CustomField
def watcherManager = ComponentAccessor.getWatcherManager()
def userManager = ComponentAccessor.getUserManager()
def cfManager = ComponentAccessor.getCustomFieldManager()
def user1 = userManager.getUserByName("user1")
def user2 = userManager.getUserByName("user2")
def customField = customFieldManager.getCustomFieldObject 'cf[11602]'
if(customField == 'Custom Field Value') {
watcherManager.startWatching(user1, issue)
watcherManager.startWatching(user2, issue)
}
I'm thinking...
def customField = customFieldManager.getCustomFieldObject 'cf[11602]'
...is the problem, but I'm not sure how to get what I need.
it's failing with this error:
Time (on server): Wed Jun 27 2018 01:00:54 GMT-0400 (EDT)
The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.
2018-06-27 01:00:54,773 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2018-06-27 01:00:54,773 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: ITCM-7854, actionId: 1, file: <inline script> groovy.lang.MissingPropertyException: No such property: customFieldManager for class: Script436 at Script436.run(Script436.groovy:15)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So, this runs without error, but I dont get my watchers... :(
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.fields.CustomField
def watcherManager = ComponentAccessor.getWatcherManager()
def userManager = ComponentAccessor.getUserManager()
def CustomFieldManager = ComponentAccessor.getCustomFieldManager()
def user1 = userManager.getUserByKey('importantUser1')
def user2 = userManager.getUserByKey('importantUser2')
def customField = CustomFieldManager.getCustomFieldObjectByName('MyCustomField')
if(customField == 'Custom Field Value') {
watcherManager.startWatching(user1, issue)
watcherManager.startWatching(user2, issue)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @David Mason!
Sorry for my super late reply!
Would you mind creating a new community question for this so the contexts of the two questions don't get too mixed and mingled for others who may look over the question?
Just send me a link to the new question that you open and I can help you over there :D
Thanks!
Aidan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
And I'm even later. Will do as I'm coming back around to the need for this.
Here's the link to the new question: https://community.atlassian.com/t5/Jira-questions/I-d-like-to-add-watchers-when-a-custom-field-value-is-true/qaq-p/1182347
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.