Setting Component Field value in JIRA groovy code


I need to set the System field values in JIRA through Groovy code (I have Component fields as "JIRA" and "Confluence" defined). I executed the below code to set the value as "JIRA" (event set for "issue updated"). I do not get any error in the logs but the value is not getting set. can anyone help for the same ? thanks


void workflowEvent(IssueEvent event) {
Issue issue = event.getIssue();

ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
IssueManager issueManager = componentManager.getIssueManager()

Project project = issue.getProjectObject()
ProjectComponent component = ComponentAccessor.getProjectComponentManager().findByComponentName(project.getId(),"JIRA")

2 answers

1 accepted

1 vote
Henning Tietgens Community Champion Mar 09, 2014

issue should be a MutableIssue and you have to store your changes. See my answer here for details. Additionally you could add log messages like

log "component: $component"

to see if everthing is working like you expect.

log.warn or log.debug etc, you probably meant.

Henning Tietgens Community Champion Mar 10, 2014

Oh.. yes :-)

Thanks Henning for your pointers, it was mutable issue and storething. By logs i meant that everything was working otherwise a big exception comes. i had removed the log messages before posting on the forum. below is the code which worked for me. once again a big thanks.

Category log = Category.getInstance(test.class)

void issueUpdated (IssueEvent event) {

def groupManager = ComponentAccessor.getGroupManager()

ComponentManager componentManager = ComponentManager.getInstance()
def customFieldManager = componentManager.getCustomFieldManager()
//def watcherManager = ComponentAccessor.getWatcherManager()

MutableIssue issue = event.issue
Project project = issue.getProjectObject()
IssueManager issueManager = componentManager.getIssueManager()

def componentJIRA = componentManager.getProjectComponentManager().findByComponentName(project.getId(),'JIRA')
def componentConfluence = componentManager.getProjectComponentManager().findByComponentName(project.getId(),'Confluence')

def Agroup=issue.getCustomFieldValue( customFieldManager.getCustomFieldObjectByName("Assignment Group"))
issueManager.updateIssue(null, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
log.debug "Blocker issue"

issueManager.updateIssue(null, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
log.debug "Exception Occured, Blank value is set for Group"



Henning Tietgens Community Champion Mar 10, 2014

Fine :-) One remark, if you call issueManager.updateIssue() you don't have to call

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Published Apr 19, 2018 in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

366 views 0 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you