Proper method to get changed values in post-function

Pepe
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.
December 18, 2011

I have added a "conditional create" clause to the Create Sub-task on Transition post-function that looks for a condition to be met in a custom field (i.e. MyCustomField was changed to "Yes") before creating a subtask. I only want to create a sub-task on the field change, not if the field has a certain value. I need to capture the rising edge from No to Yes. I've found a few different ways to capture if my custom field has changed but I'm not satisfied with the robustness of any of them since they depend where the post-function is placed in the list of post-functions in the workflow.

1. Transient Variables - the transientVars carry a changeItems list of ChangeItemBeans, however, either time or previous post-functions are needed to populate the changeItems in transientVars so one must place their post-function below the other post-functions to have access to the data (otherwise changeItems doesn't exist in transientVars or is blank). This works well for select lists but is sporadic with other custom field types like radio and checkboxes. From what I've seen in other code it is safe to get the working Issue from transient vars but not much else.

2. MutableIssue and Issue - instantiate a MutableIssue and Issue from getIssue(transientVars). Now the two objects contain the modified issue and the issue in the database. Comparing MutableIssue.mycustomfield to will show if the field value has changed only if the "write changes to db" post-function hasn't run yet.

I have found a few other methods but none seemed to be what I'm looking for. Perhaps I have to use method #1 and #2 to cover my post-function (noting that #1 is still sporadic with most custom field types I tested). What is the correct way to get the changes made during a transtion?

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
MattS
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.
December 22, 2011

You can access the values directly in the HTTPServletRequest as shown below. I think this is described in Practical JIRA Plugins (O'Reilly, 2011) and the JMWE plugin may also do this.

if (transientVars.get("originalissueobject") != null) {
	    value = cf.getValue(issue);
	} else {
	    // If this post function is on the Create transition then there
	    // is no issue to extract from the transientVars so use the 
	    // request backdoor
	    HttpServletRequest request = ServletActionContext.getRequest();
	    if (request == null) {
		log.warn("Unable to find a request while creating an issue");
		return;
	    }

	    String[] values = request.getParameterValues(cf.getId());
	    if (values == null || values.length != 1) {
		log.debug("Unable to find parameters in the request while creating an issue");
		return;
	    }

	    String valueString = values[0];
	    if (valueString == null || valueString.equals("")) {
		// Valid if no value was entered
		log.debug("Unable to find a value for "  + cf.getName() + " while creating an issue");
		return;
	    }

Pepe
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.
December 22, 2011

Thanks Matt. Just what I was looking for. I'll comment back if I'm still having issues after trying this out.

0 votes
Pepe
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.
December 21, 2011

I was really hoping someone knew. I know I'm not the first person to come up against this issue. I ended up creating a MutableIssue and Issue from getIssue(transientVars) and I compare the customfield value of interest. If they match I then fallback to looking for the changeItems in transientVars. It seems to give positive results no matter where the post-function is placed in the list of transition post-functions.

0 votes
Pepe
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.
December 18, 2011

Re-asking a previous question to be more specific.

TAGS
AUG Leaders

Atlassian Community Events