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:
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.
Atlassian has a tutorial on doing just about exactly what you want to do, here:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With