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
Answer accepted

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.

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"



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

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 13, 2019 in Marketplace Apps

Marketplace Spotlight: Marketing apps for Confluence to keep your teams working on the same page


275 views 0 7
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