10

My scenario is: One step in my jira workflow should have the ability to unschedule a task i.e. set a Fix Version to "None".

I noticed that I was not able to update fix version in a workflow post function - I don't know exactly why, but anyway I did implement a jira plugin to help me solve my problem but I know I'm going against jira structure (even java good coding practices :)). I am not sure if my implementation can cause problems, but indeed it is working in my jira instance 4.1.x.

How I've implemented a plugin to update fix version in a post function, 2 very similar ways:

public class BrandsclubPostFunctionUnschedule extends AbstractJiraFunctionProvider {
    // Here I create an empty Collection to be the new value of FixVersion (empty because I need no version in Fix Version)
    public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException {
        MutableIssue issue = this.getIssue(transientVars);
        Collection<Version> newFixVersion = new ArrayList<Version>();
            issue.setFixVersions(newFixVersion);
            issue.store();
    }
}

public class BrandsclubPostFunctionUnschedule extends AbstractJiraFunctionProvider {
    // here I clear the Collection I got from "old" Fix Version and I have to set it again to make it work.
    public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException {
        MutableIssue issue = this.getIssue(transientVars);
        Collection fixVersions = issue.getFixVersions();
        fixVersions.clear();
        issue.setFixVersions(fixVersions);
        issue.store();
    }
}

I presume that a real solution should use classes like: ChangeItemBean, ModifiedValue, IssueChangeHolder - taking as example the updateValue methods from CustomFieldImpl (from jira source code, project: jira, package: com.atlassian.jira.issue.fields).

My point of publishing this here is:

  • Does anyone know how to implement a jira plugin containing a post function to change Fix Version correctly?
Kirk Woll
  • 76,112
  • 22
  • 180
  • 195
gege
  • 371
  • 1
  • 5
  • 13

3 Answers3

4

If you want to do it properly take a look in the code for

./jira/src/java/com/atlassian/jira/workflow/function/issue/UpdateIssueFieldFunction.java processField()

Postfunctions that take input parameters are not documented yet it seems. Other places to go for code are other open source plugins.

Kuf
  • 17,318
  • 6
  • 67
  • 91
mdoar
  • 6,758
  • 1
  • 21
  • 20
1

Atlassian has a tutorial on doing just about exactly what you want to do, here:

AnneTheAgile
  • 9,932
  • 6
  • 52
  • 48
CXJ
  • 4,301
  • 3
  • 32
  • 62
0

I do it like in this snippet:

List<GenericValue> genericValueList = issueManager.getIssues(issues);
versionManager.moveIssuesToNewVersion(genericValueList, lastVersion, newVersion);
duffy356
  • 3,678
  • 3
  • 32
  • 47
Eugene
  • 1