i want to set watchers based on custopm field i'm trying this code but he don't work using script running
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.watchers.WatcherManager String userName; def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("supp") def someUser = issue.getCustomFieldValue(cf) userName=someUser def WatcherUser =ComponentAccessor.getUserManager().getUserByName(userName) def watcherManager = ComponentAccessor.getWatcherManager() watcherManager.startWatching(WatcherUser,issue)
Hi Taher,
You could also do this with a simple automation rule with Automation for JIRA (full disclosure: I'm one of the authors).
So whenever the 'My User Picker' field's value changes, this rule will add the new value to the list of watchers on the issue.
You could also change the trigger to be something like 'Issue updated' and add various conditions to the rule, to only add the watcher if say the issue matched a given workflow status.
Cheers,
Andreas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
it depends on the type of your "supp" custom field. You need to convert the result of getCustomFieldValue into a username first.
Or you can use JIRA Misc Workflow Extensions instead ;)
David
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.
As I said, it depends on the type of your custom field. Is it a user picker? A Single-select type field? Text field? Something else?
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.
Then
userName=someUser.value
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That's because ScriptRunner doesn't know the type of the someUser variable. Write everything on one line instead.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
the problem that when i show the result of watchermanager = user(user)
that's why she don't work because my user is :
User
and the result of watcherUser is
user (user)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Timing
Time (on server): Mon May 22 2017 17:37:55 GMT+0100 (Afr. centrale Ouest)
The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.
2017-05-22 18:37:55,557 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2017-05-22 18:37:55,557 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: null, actionId: 1, file: <inline script>
java.lang.NullPointerException
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:210)
at com.google.common.cache.LocalCache$LocalManualCache.invalidate(LocalCache.java:4764)
at com.atlassian.jira.issue.watchers.DefaultWatcherManager.updateWatch(DefaultWatcherManager.java:167)
at com.atlassian.jira.issue.watchers.DefaultWatcherManager.startWatching(DefaultWatcherManager.java:84)
at com.atlassian.jira.issue.watchers.DefaultWatcherManager.startWatching(DefaultWatcherManager.java:75)
at com.atlassian.jira.issue.watchers.WatcherManager$startWatching.call(Unknown Source)
at Script1573.run(Script1573.groovy:13)
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.