Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

script executing but not updating system component field with the passed value


No errors but script not updating/copying components from custom components field (customfield_15961) to system components field any help appreciated 


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.project.Project

def log = Logger.getLogger("com.acme.workflows")
log.warn("Workflow function running...")

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

// edit this query to suit
def query = jqlQueryParser.parseQuery("project = XZ AND issuekey in (XZ-25361,XZ-25345,XZ-24982)")

def search =, query, PagerFilter.getUnlimitedFilter())

log.debug("Total issues: ${}")
search.results.each { documentIssue ->
def issue = issueManager.getIssueObject(
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObject('customfield_159604');
def compName = issue.getCustomFieldValue(customField)
def issueService = ComponentAccessor.getIssueService()
def issueInputParameters = issueService.newIssueInputParameters()
def componentManager = ComponentAccessor.projectComponentManager
def projectComponentManager = ComponentAccessor.getProjectComponentManager()
//issueInputParameters.setcomponent(compName); //copy story description to description
Project project = issue.getProjectObject()

String compName2=compName.toString() //converting to string to pass to projectComponentManager.findByComponentName

def ComponentValue = projectComponentManager.findByComponentName(project.getId(), compName2)
if (ComponentValue) {



help me to make this script updates system component field

i.e I would like to copy "Unknown" value from custom components field (customfield_15961) to system components field (where system comp having ""Unknown" value) but its not working.

1 answer

0 votes

The issue you're working with is just an object in memory. You have to use either the issueManger or the issueService to persist the change to the database

I see you've instantiated the issueService and issueInputParameters but haven't used them. 

Instead of using issue.setComponent, try to use the issueInputParameters:

import com.atlassian.jira.event.type.EventDispatchOption
/* your existing code */
if (ComponentValue) {

def updateValidationResult = issueService.validateUpdate(user,, issueInputParameters
issueServerice.update(user, updateValidationResult, EnventDispacthOption.DO_NOT_DISPATCH, false)


If you want event and email dispatched, you can omit those last 2 parameters or set them accordingly.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Apps & Integrations

How we use Jira Service Management for our recruitment process! - Part 2

It is never about setting up a process and being done with it. Rather, the focus should always be on optimizing it for the best outcomes. Thus, we didn’t stop at setting up JSM for our recruitment pr...

194 views 0 5
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you