results.getIssues().each { issue = componentManager.getIssueManager().getIssueObject(it.getKey()) fieldLayoutItem = new FieldLayoutItemImpl.Builder().setOrderableField(field).build() currentValue = issue.getFixVersions() field.updateIssue(fieldLayoutItem, issue, EasyMap.build(field.getId(),new ArrayList())); field.updateValue(fieldLayoutItem, issue, new ModifiedValue(currentValue, new ArrayList()), new DefaultIssueChangeHolder()); storeAndIndex(issue); } def storeAndIndex(issue) { imp = ImportUtils.isIndexIssues() ImportUtils.setIndexIssues(true) issue.store() componentManager.getIndexManager().reIndex(issue.getGenericValue()) ImportUtils.setIndexIssues(imp) }
I can't get fixVersions to persist. Other fields seem to work fine but not fixVersions.
I'm trying to clear out the field for several issues. I've tried setFixVersions() on the issue and removevaluefromissue on the field
same problem with persistance however I try. I'm running 4.3.3.
Community moderators have prevented the ability to post new answers.
The correct answer is that archived versions can not be disassociated from issues so my code worked but was not enough to solve my problem. Changing my code to first unarchive any version that was included in the fixVersion prior to setting the field and then setting it back resulted in the desired outcome
def archVers = [] results.getIssues().each { issue = componentManager.getIssueManager().getIssueObject(it.getKey()) fieldLayoutItem = new FieldLayoutItemImpl.Builder().setOrderableField(field).build() currentValue = issue.getFixVersions() currentValue.each { version -> if (version.isArchived()) { archVers.add(version) version.setArchived(false) } } field.updateIssue(fieldLayoutItem, issue, EasyMap.build(field.getId(),new ArrayList())); field.updateValue(fieldLayoutItem, issue, new ModifiedValue(currentValue, new ArrayList()), new DefaultIssueChangeHolder()); storeAndIndex(issue); } archVers.each { version -> version.setArchived(true) }
I don't know what "field" is in your context, but to set the fixVersion you could use issue.setFixVersions(Collection<com.atlassian.jira.project.version.Version>).
Henning
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
<rainbows and unicorns>
I was unclear, I tried issue.setFixVersions(Collection<version>). I am able to set the field to what I want but it does not persist when implemented in the same manner as I have set and persisted other fields.
'field' is a reference to the field object I am trying to set as in
field = componentManager.getFieldManager().getOrderableField("fixVersions")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried this code on our test instance and it works fine.
import com.atlassian.jira.ComponentManager 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.util.map.EasyMap def field = ComponentManager.instance.getFieldManager().getOrderableField("fixVersions") def issue = ComponentManager.instance.getIssueManager().getIssueObject('INH-1488') def fieldLayoutItem = new FieldLayoutItemImpl.Builder().setOrderableField(field).build() def currentValue = issue.getFixVersions() field.updateIssue(fieldLayoutItem, issue, EasyMap.build(field.getId(),new ArrayList())) field.updateValue(fieldLayoutItem, issue, new ModifiedValue(currentValue, new ArrayList()), new DefaultIssueChangeHolder()) storeAndIndex(issue) def storeAndIndex(MutableIssue issue) { imp = ImportUtils.isIndexIssues() ImportUtils.setIndexIssues(true) issue.store() ComponentManager.instance.getIndexManager().reIndex(issue.getGenericValue()) ImportUtils.setIndexIssues(imp) }
INH-1488 is an issue key of an issue with a version set. After runing this script through script runner, fixVersion is empty...
Henning
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm glad it works for you. So that means its not my code.
So what is it? Glad you asked. The answer seems to be archived versions. It appears you can not diassociate an archived version from an issue so you need to unarchive the version make the issue change then re-archive.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thanks for the help Henning. knowing that it worked on your system and being reminded that trying it on one issue was a good idea (duh) lead to the answer I needed.
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.