Hi Community,
So... I am planning to move all Feature issues to Epic.
All Features have value in the Parent Link field.
I want to make sure that all the Epic link fields are populated with the same value as from the Parent Link once we move he issues to Epic.
My concern is that there are 100s of issues under Feature issue type and I know if I want to do that manually it will take ages!
Can you please help on what is the best practice for this?
Is it Automation rule? Scriptrunner? API?
Thank You
Hi @Nivine Alaeddine
Scriptrunner would allow a bulk change in the script console, and based on the logic required this is probably your best bet.
Bulk edit may do this for you as well, I'd suggest testing this out.
I don't see how an automation would fix this, but it may be possible.
Thank you for your response.
I have been searching for samples of Script-runner, but no luck.
Can you please share a sample that I can start with?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Nivine Alaeddine I don't have an environment to test for you but it will be very much like this script here. But rather than updating the field, copy the value to the Epic Link field. One thing that this doesn't answer below is the value for the epic itself, and from what I've seen you need this re: the epic issue id there's a routine to update the Epic Link and it required the epic issue id (see bottom of post for second script) you may have to build out a way to get that key.
All this can be found in the Scriptrunner Library
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.search.SearchQuery
// Issues returned from JQL that will get altered
final searchQuery = "project = TEST AND "Parent Link" != "null" " // Build your query to get your issues
// The name of the custom field to alter add Epic Link Field here
//final customFieldName = "TextFieldA"
final customFieldName = "Epic Link"
// The new value to set
final newValue = "Love Groovy" // make this equal to the Epic Link Value found in the issue
// Get the custom field
def customField = ComponentAccessor.customFieldManager.customFieldObjects.findByName(customFieldName)
assert customField : "Could not find custom field with name ${customFieldName}"
// Get some components
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def issueManager = ComponentAccessor.issueManager
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
// Perform the JQL search
def query = jqlQueryParser.parseQuery(searchQuery)
def searchResults = searchProvider.search(SearchQuery.create(query, user), PagerFilter.unlimitedFilter)
// Iterate all results to update each issue Make changes here to update the EpicLinkfield and not the custom field
searchResults.results.each { documentIssue ->
def key = documentIssue.document.fields.find { it.name() == "key" }.stringValue()
def issue = issueManager.getIssueObject(key)
customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), newValue), new DefaultIssueChangeHolder())
}
Second Script
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
// the issue key of the issue that will be added to an epic
final String issueKey = "JRA-1"
// the issue key of the epic issue
final String epicIssueKey = "JRA-2"
// the name of the custom field to update (in our case is the Epic Link)
final String epicLinkFieldName = "Epic Link"
def issueManager = ComponentAccessor.issueManager
def issue = issueManager.getIssueByCurrentKey(issueKey)
def epic = issueManager.getIssueByCurrentKey(epicIssueKey)
def targetField = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).findByName(epicLinkFieldName)
assert targetField : "Could not find custom field with name $epicLinkFieldName"
targetField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(targetField), epic), new DefaultIssueChangeHolder())
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you @Craig Nodwell
I will give it a try and see if that will work. Will defo update you here if it is a successful one.
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.