Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Set assignee on parent based on next subtask

I'm not a developer and could use some help.

I'm trying to look at all subtasks on a parent issue and use a post function on the "Pass" transition to find the next subtask, look at who it is assigned to, and reassign the parent issue to the person assigned to the next subtask.

For example, 

Parent - ParentAssignee

  • Subtask1 - Subtask1Assignee - Status is Done
  • Subtask2 - Subtask2Assignee - just transition through Pass transition
  • Subtask3 - Subtask3Assignee

 

If the user moves Subtask2 through Pass, as a postfunction, I want to look at Subtask3 and see who it is assigned to (Subtask3Assignee) and then reassign the parent to Subtask3Assignee.

I've pulled together code from various things I've done before and have successfully gotten a list of subtasks, my current issue is changing the subtask number that is an integer, back to the subtask key to then get the assignee.

Here's what I have so far that is cycling through the subtasks:

import com.atlassian.jira.component.ComponentAccessor

log.setLevel(org.apache.log4j.Level.DEBUG)

def issue = ComponentAccessor.issueManager.getIssueByCurrentKey("OAK-25198")
log.debug "issue is $issue"
def parent = issue.getParentObject()
log.debug "parent issue is $parent"

def subTasks = parent.getSubTaskObjects()

for (int i = 0; i < subTasks.size(); i++) {
def subtaskNumber = subTasks[i].getKey().findAll( /\d+/ )*.toInteger()[0]
log.debug "subtaskNumber is $subtaskNumber"

def nextSubtaskNumber = subtaskNumber + 1
log.debug "Next subtask Issue number is $nextSubtaskNumber"
}

My log looks as follows:

2021-07-21 16:20:38,654 DEBUG [runner.ScriptBindingsManager]: issue is OAK-25198 2021-07-21 16:20:38,658 DEBUG [runner.ScriptBindingsManager]: parent issue is OAK-25197 2021-07-21 16:20:38,661 DEBUG [runner.ScriptBindingsManager]: subtaskNumber is 25198 2021-07-21 16:20:38,661 DEBUG [runner.ScriptBindingsManager]: Next subtask Issue number is 25199 2021-07-21 16:20:38,661 DEBUG [runner.ScriptBindingsManager]: subtaskNumber is 25200 2021-07-21 16:20:38,661 DEBUG [runner.ScriptBindingsManager]: Next subtask Issue number is 25201 2021-07-21 16:20:38,661 DEBUG [runner.ScriptBindingsManager]: subtaskNumber is 25199 2021-07-21 16:20:38,661 DEBUG [runner.ScriptBindingsManager]: Next subtask Issue number is 25200

 

So I'm able to cycle through the subtasks, and add 1 to the subtask to find the next one. The problem is, my issue key is an integer. So I think I need to get it back to an issue key and then find the assignee on nextSubtaskNumber.

I've tried a couple of things, but no luck yet. Any developers out there able to help me? :)

Many thanks!!
Laurie

1 answer

I'm getting closer... now all I need to do is assign the parent issue - can't seem to figure out the correct code for that...

import com.atlassian.jira.component.ComponentAccessor

log.setLevel(org.apache.log4j.Level.DEBUG)

def issue = ComponentAccessor.issueManager.getIssueByCurrentKey("OAK-25198")
log.debug "issue is $issue"
def parent = issue.getParentObject()
log.debug "parent issue is $parent"

def subTasks = parent.getSubTaskObjects()

for (int i = 0; i < 1; i++) {
def subtaskNumber = subTasks[i].getKey().findAll( /\d+/ )*.toInteger()[0]
log.debug "subtaskNumber is $subtaskNumber"

def nextSubtaskNumber = subtaskNumber + 1
log.debug "Next subtask Issue number is $nextSubtaskNumber"

def nextSubtaskUser = subTasks[i+1].getAssignee()
log.debug "Next subtask user is $nextSubtaskUser"

parent.setAssignee(nextSubtaskUser)
log.debug "parent issue was reassigned to $nextSubtaskUser"
}

 

That last line (parent.setAssignee(nextSubtaskUser)) isn't working.

Thoughts?

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.5.9
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you