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.bc.issue.search.SearchService
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.setLevel(Level.DEBUG)
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 = searchService.search(user, query, PagerFilter.getUnlimitedFilter())
log.debug("Total issues: ${search.total}")
search.results.each { documentIssue ->
def issue = issueManager.getIssueObject(documentIssue.id)
log.debug(issue.key)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObject('customfield_159604');
def compName = issue.getCustomFieldValue(customField)
log.debug(compName)
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) {
log.debug(ComponentValue)
issue.setComponent([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.
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) {
log.debug(ComponentValue)
issueInputParameters.setComponentsIds(ComponentValue.id)
def updateValidationResult = issueService.validateUpdate(user, issue.id, issueInputParameters
if(updateValidationResult.isValid()){
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.