Post Function(Create subtask) with a condition

Alejandra March 31, 2021

Hello,


I'm configuring a new postfunction with Scriptrunner to create subtasks. I need to check first if the issue has subtasks of the same type. I have added this condition
issue.subTaskObjects.any{ it.issueType.name == "Imputacion de Horas" }
I thought that checked if the issue has subtask of "Imputación de horas", but if the issue has another subtask doesn't generate the subtask. 

Any ideas?

Thank you!! 

1 answer

1 accepted

0 votes
Answer accepted
Hana Kučerová
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 31, 2021

Hi @Alejandra ,

please, just to be perfectly clear, how this should work...

You want to check, if there's at least one subtask with type "Imputacion de Horas"? No matter which types the other possible subtasks have?

Thank you.

Alejandra April 3, 2021

Hi @Hana Kučerová ! 

Yes that's correct! i only want to chet that type of subtask! 

Thanks! 

Hana Kučerová
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 5, 2021

Hi @Alejandra ,

this is really weird, I believe your code should work.

I've tested this code using console (with KEY = issue key and NAME = sub-task issue type name):

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue

IssueManager issueManager = ComponentAccessor.getIssueManager()
Issue issue = issueManager.getIssueObject("KEY")
issue.subTaskObjects.any{ it.issueType.name == "NAME" }

If issue with key KEY has at least one sub-task with type NAME, the last row returns true.

Like Alejandra likes this
Alejandra April 12, 2021

thanks for your answer. We will still trying :)

Suggest an answer

Log in or Sign up to answer