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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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

Edited

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.

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 29, 2021

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.

TAGS
AUG Leaders

Atlassian Community Events