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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,558,919
Community Members
 
Community Events
184
Community Groups

Jira Expressions in Workflow Validators

I'm having an issue with Jira Expressions. I'm unclear on how to use if statements.

Goal: I've got an issue type of "Groundwork" that uses a workflow that is standard for all subtasks. When this groundwork status is updated to "Complete", I want to check that all sibling subtasks are assigned (because this is just part of the responsibilities for the person who completes the groundwork task). If any are Unassigned this transition should fail.

Steps Taken:

Problem:

  • I'm unsure how to really use functions or if statements in Jira Expressions. I'm getting the following error and I'm unsure how to translate this into Jira Expressions. Error: "Jira expression failed to parse: line 3, column 1:\nexpression expected, reserved keyword 'if' encountered."
passesCondition = true

// if issue is groundwork type
if (issue.issueType.name.match('^(Groundwork)$') != null) {

// get parent
parentIssue = issue.parent

// get subtasks
def subTasks = parentIssue.getSubTaskObjects()

// for each subtask
subTasks.each {
// if not assigned
if (it.assignee == null)
passesCondition = false
}
}
passesCondition

Questions:

1. How can I translate the code above to Jira Expressions?
2. Are there any other alternatives, without Jira Automation?

validators.png

3 answers

1 accepted

4 votes
Answer accepted

Final answer:

If issue type is not Groundwork, automatically pass, otherwise, check sibling subtasks and assignee.

issue.issueType.name.match('^(Groundwork)$') == null || (issue.issueType.name.match('^(Groundwork)$') != null && issue.parent.subtasks.filter(subtask => subtask.assignee != null).length == issue.parent.subtasks.length)? true : false

This doesn't address the OP's original situation or requirement but posting in case this helps others. The suggestion from @perla.miranda put me on the right tracks.

My requirement was to validate Custom Field A and:

- If it was null, the issue could transition

- If it was not null, make Custom Field B required.

This is the simple validator code that worked for me:

issue.customfield_A == null || issue.customfield_A != null && issue.customfield_B != null

0 votes
Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Aug 22, 2022 • edited

Hi @perla.miranda  Kindly create a separate workflow for issue type "Groundwork" and apply following script in scripted validator on Complete transition :- 

  issue.subtasks.filter(subtask => subtask.assignee != null).length == issue.subtasks.length

Type an error message to show when the validator fails.

Thanks

V.Y

@Vikrant Yadav Can you elaborate on this?

Groundwork is a "subtask" issue type, so this issue will not have any subtasks. I need to check that the siblings are assigned.

Also, the workflow is exactly the same as all other subtasks, so would I need to create a different workflow just to add a validator? Is there no way to check this with if statements?

The solution of duplicating a workflow just for a validator doesn't seem ideal. The Jira expression documentation mentions the following code for checking issue type:

issue.issueType.name.match('^(Groundwork)$')!= null

  I'm just unsure how to use this in combination with the other things that I need.

Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Aug 22, 2022

@perla.miranda  Okay, i thought "Groundwork" is a Parent task. 

Groundwork is subtask issue type, you want to check that all subtasks  of "Groundwork" subtask issue type only must be assigned before moving to complete status, right ? 

No. Please look at the details in the post. Here is an explanation. Groundwork is a subtask. There are other sibling subtasks.

For example:

- Parent Issue
       - Groundwork subtask (when this is marked as complete, check that all other sibling subtasks are assigned)
       - subtask
       - subtask

Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Aug 24, 2022

@perla.miranda  Checked with Atlassian experts and documents, it's not possible to add if statement in JIRA expression. Meanwhile i suggest you to create a separate workflow for Groundwork issue type and apply above scripted validator. 

Thanks

I took the code you mentioned before and modified it. I ended up doing the following which works. No need for a separate workflow since all subtasks use the same one and Groundwork is a subtask. Thanks!

 


issue.issueType.name.match('^(Groundwork)$') == null || (issue.issueType.name.match('^(Groundwork)$') != null && issue.parent.subtasks.filter(subtask => subtask.assignee != null).length == issue.parent.subtasks.length)? true : false

 

Like # people like this
Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Aug 24, 2022

@perla.miranda  Great 😊 , Finally you made it. 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events