Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Post function not evaluated in other post function

Sander Spoelstra
Contributor
October 12, 2022

Hi,

tl;dr
if I fill a field in the first post function of a transition, and then create a subtask in a second post function of that same transition, the value of the field is not copied into the subtask. How can I force this?

 

Full explanation:

I'm trying to prevent people from reviewing their own work in Jira. I'm not talking about code-reviews or something like that, but a procedural check by someone else to see that we have not forgotten anything and that all systems are running correctly before releasing it to our customers. As we work with large teams / departments in a single project in Jira, the pool of potential review candidates is large and varies often. 

The workflow is pretty straight forward:

  1. Backlog
  2. Analysis
  3. In progress
  4. Done

Between step 2 and 3, a variable number of subtasks is automatically created depending on what needs to happen (e.g. Design, Documentation, Implementation, Test and Review).

To prevent people from reviewing their own work I've added a couple of post functions in the transition between 2 and 3. First off, I use a simple script to populate a custom user picker field 'Current user' with the account of the person that has clicked the transition. Second, I create a subtask 'Review' where I copy all fields in. To prevent the self-review, I make sure that the transition in the review subtask cannot be performed if the user equals the value of the custom field.

post-functions.png

Main ticket:
current user - main ticket.png

Sub-task:
current user - sub-task.png

The issue then is that despite the first post function working well (the 'Current user' field is filled with the correct information), the field remains empty in the subtask.

 

I tried to add a third post function that explicitly copies the value from main task into the subtask, but to no avail.

When I split the two actions (fill the field 'Current user' one transition before, and then create a subtask in the next transition), everything works exactly like it's supposed to, but I would hate to add a status just to fix this problem.

 

Is there a way to get this all done in a single transition?

1 answer

1 accepted

1 vote
Answer accepted
Joe Pitt
Community Champion
October 12, 2022

Try moving the update post function right after the first one. I use a post function to set the date in a custom field but that only works if the update function is before I set the date. Otherwise the date is set to the last time the issue was updated. 

Sander Spoelstra
Contributor
October 12, 2022

Edit: scratch that! The update any field from JSU allows me to set the value with %%CURREN_TUSER%% and that works. 

 

So solution accepted!

 

P.s. still very strange that this works, but the script that essentially does the exact same thing doesnt.

 

Not sure I follow. The standard 'Update Issue Field' post-function does not allow for custom fields to be updated. The 'Update Any Issue Field (JSU)' from the JSU addon, does not allow for a script to be inserted. ScriptRunner has no update field post-function other than what I'm already using.

The script btw is:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

def Issue = issue as MutableIssue
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def customFieldManager = ComponentAccessor.customFieldManager
def assignee = issue.assignee

def currentUser = customFieldManager.getCustomFieldObjectsByName("Current user")[0]


issue.setCustomFieldValue(currentUser, loggedInUser)

Suggest an answer

Log in or Sign up to answer