Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Set user custom Field Value

Rita YOUNES [Infosysta]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 3, 2016

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

 

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Franck LAMBEZ February 3, 2016

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

Rita YOUNES [Infosysta]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 3, 2016

ScreenHunter_59 Feb. 04 12.48.jpg

Rita YOUNES [Infosysta]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 3, 2016

Hello @Franck LAMBEZ

I can get the value of TeamLeader

I got the following error.

Any advice?

Thanks

Franck LAMBEZ February 4, 2016

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);

 

 

Rita YOUNES [Infosysta]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 4, 2016

@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,

Rita YOUNES [Infosysta]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 4, 2016

@Franck LAMBEZ Please note that I have JIRA 7 and issue.genericValue is not working 

Thanks you 

TAGS
AUG Leaders

Atlassian Community Events