Upgrading Workflow Plugins for JIRA 3.2

If you have written a workflow plugin (Validator or Post Function) for JIRA 3.0 or 3.1 you might have to modify it to make it work for JIRA 3.2. If you are getting ClassCastExceptions while transitioning issues through workflow after upgrading to JIRA 3.2 there is a high chance that this document is what you are looking for.

Workflow Conditions still use GenericValues for issues, so if you have written a custom Workflow Condition it should work with JIRA 3.2

Regular Workflow Transition

For a regular workflow transition in JIRA 3.1 the transientVars map contained a GenericValue object that represented an issue. The transientVars Map also contained the fields that were changed during the transition (if any), namely Fix Versions, Assignee and Resolution.

In JIRA 3.2 an Issue object has been created, and all the changes that have been made to the issue can be obtained from the Issue object:

Issue issue = (Issue) transientVars.get("issue");
Map modifiedFields = issue.getModifiedFields();

Please note that in version of JIRA 3.1 and earlier the transientVars map contained a GenericValue object with the key "issue". If your code does something like:

GenericValue issue = (GenericValue) transientVars.get("issue");

This will cause a ClassCastException in JIRA 3.2. You need to cast the object to Issue instead of GenericValue. If you need to get the GenericValue of the issue, you can do that by calling:

GenericValue issueGV = issue.getGenericValue();

As mentioned earlier, the modifiedFields map contains all the fields that have been updated during the workflow transition. The keys of the modifiedFields map are ids of fields (please see com.atlassian.jira.issue.IssueFieldConstants) that have been modified, and the values of the modifiedFields map are ModifiedValue objects. A ModifiedValue object represents an updated field. The object stores the old and the new value of the field for the issue. You can use this object like so

Map modifiedFields = issue.getModifiedFields();
for (Iterator iterator = modifiedFields.keySet().iterator(); iterator.hasNext();)
{
    String fieldId = (String) iterator.next();
    ModifiedValue modifiedValue = (ModifiedValue) modifiedFields.get(fieldId);
    // Old value of the field
    Object oldValue = modifiedValue.getOldValue();
    // New Value of the field
    Object newValue = modifiedValue.getNewValue();
    
}

Please note, that the comment and commentLevel are still recorded in the modifiedFields map.

Initial Workflow Transition

An initial workflow transition is the transition that creates an issue.

In JIRA 3.1 and earlier the transientVars map contained the field values that should be used to create an issue. In JIRA 3.2 the value of the fields are recorded in the Issue object rather than in the transientVars map. You can use various getter methods to retrieve values of these fields. For example, if you need to get issue's description, instead of doing:

String description = (String) transientVars.get(IssueFieldConstants.DESCRIPTION);

do this:

Issue issue = (Issue) transientVars.get("issue");
String description = issue.getDescription()

Was this helpful?

Thanks for your feedback!

Why was this unhelpful?

Have a question about this article?

See questions about this article

Powered by Confluence and Scroll Viewport