CustomField Storage when created by Workflow Post Function at initial Workflow Transition

XMLWordPrintable

      With previous release of JIRA 3.0.3, I implemented differents post-function in ours Workflows, such as

      <post-functions>
         <function type="class">
            <arg name="class.name">com.bnpparibas.jira.function.issue.MyCustomFieldFunction</arg>
         </function>
      </post-functions>

      and a Class MyCustomFieldFunction as follow :

      public class MyCustomFieldFunction implements FunctionProvider {
      	...
      	public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException {
      		GenericValue issue = (GenericValue) transientVars.get("issue");
      		MyCustomFieldHelper.createMyCustomField(issue);
      	}
      	...
      }

      calling a Helper MyCustomFieldHelper in charge of CustomField Creation

      public class MyCustomFieldHelper {
      	...
      	public static ChangeItemBean createMyCustomField(final GenericValue issue) {
      		ChangeItemBean cib = null;		
      		// Retrieve MY_FIELD Custom Field
      		CustomField cf = cfMgr.getCustomFieldObjectByName(ModelConstants.CF_MY_FIELD);
      		if (cf.getValue(issue)==null) {
      			cib = cf.updateValue(issue, "A New Value");
      		}
      		return cib;
      	}
      	...
      }

      For JIRA 3.4.3 migration (and soon 3.5.1), I have modified these classes as follow :

      public class MyCustomFieldFunction implements FunctionProvider {
      	...
      	public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException {
      		Issue issue = (Issue) transientVars.get("issue");
      		MyCustomFieldHelper.createMyCustomField(issue);
      	}
      	...
      }

      calling a Helper MyCustomFieldHelper in charge of CustomField Creation

      public class MyCustomFieldHelper {
      	...
      	public static ChangeItemBean createMyCustomField(final Issue issue) {
      		IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
      		// Retrieve MY_FIELD Custom Field
      		CustomField cf = cfMgr.getCustomFieldObjectByName(ModelConstants.CF_MY_FIELD);
      	
      		if (cf.getValue(_issue)==null) {
      			ModifiedValue modifiedValue = new ModifiedValue(null,"A New Value");
      			if (_issue instanceof MutableIssue) {
      				((MutableIssue)_issue).setCustomFieldValue(cf,modifiedValue.getNewValue());
      			} else {
      				cf.updateValue(null,_issue, modifiedValue,changeHolder);
      			}
      		}
      		return changeHolder.getChangeItems();
      	}
      	...
      }

      N.B. : Test concerning Instance Of Issue, because this Helper is not only used by Workflow Functions !

      Since this modification, created CustomFields were not updated in Database, when they are created at first transition.

      After some search, it appears that this update is perform by the function com.atlassian.jira.workflow.function.issue.GenerateChangeHistoryFunction ...

      <workflow-function key="generatechangehistory-function" name="Generate Change History" class="com.atlassian.jira.plugin.workflow.WorkflowNoInputPluginFactory">
           <description>Updates change history for an issue and stores the issue to the database.</description>
      
           <function-class>com.atlassian.jira.workflow.function.issue.GenerateChangeHistoryFunction</function-class>
      
           <orderable>false</orderable>
           <unique>true</unique>
           <deletable>false</deletable>
           <weight>300</weight>
           <default>true</default>
           <addable>non-initial</addable>
      
           <resource type="velocity" name="view" location="templates/jira/workflow/com/atlassian/jira/plugin/generatechangehistory-function-view.vm"/>
      </workflow-function>

      Sadely, this post-function is mentionned as not useable in the initial transition Create Issue.
      I have made the test by adding manualy the post-funtion in XML Workflow definition, and concerned Custom Field are correctly updated in database.

      What are the reason / risk to use this function in initial transition's post-functions ?

      Regards
      Vincent

              Assignee:
              Unassigned
              Reporter:
              Vincent Thoulé
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: