Hi,
some users would like to automaticaly add a fix version to stories that are created in an epic with a fix version. I did the script below as a custom listner on the 'Issue Created' event :
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.CustomFieldType
import com.atlassian.jira.issue.fields.CustomField
import org.apache.log4j.Category
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.fields.layout.field.FieldLayoutItemImpl;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
import com.atlassian.jira.util.ImportUtils;
import com.atlassian.jira.project.version.VersionManager;
log.setLevel(org.apache.log4j.Level.INFO);
log.info("Script Runner: On IssueCreated -> TEST JCG");
def issue = event.getIssue();
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
def issueManager = ComponentAccessor.getIssueManager();
def versionManager = ComponentAccessor.getVersionManager();
// Check if Issue Type is Story
if (issue.getIssueType().getName() == "Story" ) {
// Get Custom Field as string (Epic Link)
def epicLinkCf = customFieldManager.getCustomFieldObjectByName("Epic Link")
// Get Custom Field Value as String
CustomField epicLink = customFieldManager.getCustomFieldObjectByName('Epic Link');
String EpicName = issue.getCustomFieldValue(epicLink);
if(EpicName){
// Get Epic from Issue
def epicIssue = issue.getCustomFieldValue(epicLinkCf) as Issue
// Get Fix Version from Epic
def currentValue = epicIssue.getFixVersions()
log.info("Set version to: " + currentValue);
// Set Fix Version to Story
def collection = versionManager.getFixVersionsFor(issue);
log.info("Current fixed versions: " + collection);
versionManager.updateIssueFixVersions(issue, currentValue);
versionManager.updateIssueAffectsVersions(issue, currentValue);
collection = versionManager.getFixVersionsFor(issue);
log.info("New fixed versions: " + collection);
// issue.setFixVersions(currentValue);
}
}
This wirks all right and the field Fix Version on my new storie is correctly set. However, I I then go to my board and filter on the version, the new story is not displayed. If I go to the version tab the story is not displayed. If I do the search on issues that have this version as fix version, the story is not displayed.
If I go to the issue tab, deleted the fix version to reset it to the version value, everything is fine. I'm sure I'm missing something somewhere but can't find it...
Can anyone help me on this ?
Hi, it sounds you need re-indexing the issue :
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.issue.index.IssueIndexingService
boolean wasIndexing = ImportUtils.isIndexIssues();
IssueIndexingService indexing = (IssueIndexingService) ComponentAccessor.getComponent(IssueIndexingService.class)
indexing.reIndex(issue)
ImportUtils.setIndexIssues(wasIndexing)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Perfect!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Can you confirm that when a fix version is set via your script, this change is reflected in your issue's change history?
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.