Hello ,
I have a user property called Team Leader and once I create an issue I want the team lead (user picker custom field ) to take this value and put it as watchers to the issue.
Not able to update the field value, The method is not working.
I Tried to write this code but the update Value is not working.and also the watch is not working
Any advice please??
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.AbstractIssue
import com.atlassian.jira.issue.fields.layout.field.FieldLayout
import com.atlassian.jira.issue.customfields.manager.OptionsManager
def userPropertyManager = ComponentAccessor.getUserPropertyManager()
def userManager = ComponentAccessor.getUserManager()
def appUser = userManager.getUserByName(issue.reporter.name)
def TeamLeader = userPropertyManager.getPropertySet(appUser).getString("jira.meta.TeamLeader")
def watcherManager = ComponentAccessor.getWatcherManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def tgtField = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Team Lead'}
def changeHolder = new DefaultIssueChangeHolder();
tgtField.updateValue(null, issue, new ModifiedValue("", TeamLeader),changeHolder);
def watcherManager = ComponentAccessor.getWatcherManager()
watcherManager.startWatching(TeamLeader,issue.getGenericValue())
Rita
Community moderators have prevented the ability to post new answers.
Hello Rita,
I think you missed one step:
def nuser = userManager.getUserByName(TeamLeader)
watcherManager.startWatching(nuser,issue.getGenericValue())
Are you also sure you well get the string TeamLeader?
Regards,
Franck
ScreenHunter_59 Feb. 04 12.48.jpg
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Franck LAMBEZ
I can get the value of TeamLeader
I got the following error.
Any advice?
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you please try this:
def nuser = userManager.getUserByName(TeamLeader)
def assigneeWatcher = userManager.getUserObject(nuser);
watcherManager.startWatching(assigneeWatcher ,issue.getGenericValue())
If this don't work please read the following :
In fact I have a code that works (when changing assignee, the old one keeps whatching):
def assignee = issue.assigneeId;
// somehow,we have to find out the JIRA Id of your TeamLeader
def assigneeWatcher = userManager.getUserObject(assignee);
watcherManager.startWatching(assigneeWatcher , issue.genericValue);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Franck LAMBEZ the custom field called 'Team Lead'
Teamleader is the the value of user property. am not able to update the value on creation of issue to put it as watcher.
Awaiting your feedback,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Franck LAMBEZ Please note that I have JIRA 7 and issue.genericValue is not working
Thanks you
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.