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

how to set fixVersions with groovy through scriptrunner?

Justin Shapiro
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 30, 2012
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.

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Justin Shapiro
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 30, 2012

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)
}

1 vote
Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 30, 2012

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

Justin Shapiro
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 30, 2012

<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")

Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 30, 2012

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

Justin Shapiro
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 30, 2012

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.

Justin Shapiro
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 30, 2012

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.

TAGS
AUG Leaders

Atlassian Community Events