I need to update a custom field's value on all the child issues (feature issues) that are connected to a project, so that they match their parent whenever it (the project issue) is updated.
I have been able to access all of the child issues of my given project. My second 'log.debug' below returns a List (array?) of the children issues linked to the project 'DEVP'...
I need automatically update a custom field on ALL of these children issues when that same field is updated on the parent...
if (issue.projectObject.key == "DEVP"){
log.debug (issue)
log.debug (issueLinkManager.getOutwardLinks(issue.id))
//field.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(field), field), changeHolder)
}
Can I implement updateValue() multiple issues at once? Do I need a loop?
Entire script:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.issuetype.IssueType
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.bc.issue.*
import static com.atlassian.jira.workflow.TransitionOptions.Builder;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.link.IssueLink
import org.apache.log4j.Logger
import org.apache.log4j.Level
MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject("DEVP-384");
IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager();
def changeHolder = new DefaultIssueChangeHolder()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager();
def field = customFieldManager.getCustomFieldObjects(event.issue).find { it.name == "Issue Category" }
def issueService = ComponentAccessor.getIssueService()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueCatValue = issue.getCustomFieldValue(field)
def log = Logger.getLogger("com.acme.CreateSubtask")
log.setLevel(Level.DEBUG)
if (issue.projectObject.key == "DEVP"){
log.debug (issue)
log.debug (issueLinkManager.getOutwardLinks(issue.id))
//field.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(field), field), changeHolder)
}
I can access my Custom Field, the Project, and all of it's children...but I am having trouble putting these parts together. Thank you.
Yes you are correct. A loop was necessary, as I needed to access each linked issue singularly and then update the field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Katrina Thacker For some reason this script is no longer in production and I cannot locate it. But this script is similar in that it defines some custom fields and sends changes down the chain when the parent field is updated
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.issue.search.SearchQuery
import com.atlassian.jira.issue.search.DocumentWithId
import org.apache.log4j.Logger
import org.apache.log4j.Level
def log = Logger.getLogger("com.acme.BusLine")
log.setLevel(Level.DEBUG)
Issue issue = event.issue
def key = issue.getKey()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def BLfield = customFieldManager.getCustomFieldObjects(event.issue).find { it.name == "Business Line" }
def issueService = ComponentAccessor.getIssueService()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def parentLink = customFieldManager.getCustomFieldObjectsByName('Parent Link')[0]
def customFieldValue = issue.getCustomFieldValue(parentLink)
def parentKey = (String) customFieldValue
def parentIssue = issueManager.getIssueObject(parentKey)
def parentValue = issue.getCustomFieldValue(BLfield)
// YOU CAN PUT WHATEVER IN THE BELOW LOG METHOD TO SEE WHAT THE VALUE OF YOUR FIELDS ARE AT RUNTIME
log.debug("ParentLink Value = " + customFieldValue)
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def jqlSearch = "issuetype in (Feature,FTS) and issuekey in childIssuesOf(" + key + ")"
def query = jqlQueryParser.parseQuery(jqlSearch)
def results = searchService.search(user,query, PagerFilter.getUnlimitedFilter())
// LOOP THROUGH THE RESULTS
results.getResults().each {documentIssue ->;
def childIssue = issueManager.getIssueObject(documentIssue.id)
def changeHolder = new DefaultIssueChangeHolder()
def childValue = childIssue.getCustomFieldValue(BLfield)
def issueIndexManager = ComponentAccessor.getComponent(IssueIndexingService)
//UPDATE THE FIELD'S VALUE
BLfield.updateValue(null, documentIssue, new ModifiedValue(childValue, parentValue), changeHolder)
issueIndexManager.reIndex(documentIssue)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.