Workflow validation of a status of a particular set of subtasks

Enrique November 21, 2024

Hello,

 

I have several transition cycle and for each a set of subtasks have to be completed, therefore a transition must not be performed if  any of their related subtasks is pending.

I have tried several syntaxes but none is working.

Using CustomFieldName

issue.subtasks.filter(subtask => subtask.issueType.name == 'TypeOfSubTasks' && subtask.issueType.TypeOfActivity.value == 'ABC' && subtask.status.name != 'Closed').length == 0

Using CustomFiled ID

issue.subtasks.filter(subtask => subtask.issueType.name == 'Sub Test Execution' && subtask.issueType.customfield_5555.value == 'ABC' && subtask.status.name != 'Closed').length == 0

I set this in the workflow as VALIDATOR selecting ScriptRunner Script

I will appreciate any help to implement this control to the workflow.

Thank you in advance.

Enrique

3 answers

2 accepted

1 vote
Answer accepted
Salih Tuç
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.
November 21, 2024

Hi @Enrique ,


I think you are already there. Just remove the issueType on second condition:

issue.subtasks.filter(subtask => subtask.issueType.name == 'Sub Test Execution' && subtask.customfield_5555.value == 'ABC' && subtask.status.name != 'Closed').length == 0

 

Enrique November 22, 2024

Hi @Salih Tuç 

Thank you for responding, 

If I removed that condition, the validation would be considering all possible subtasks created for that parent ticket, and we have several.  Therefore I have to limit my control to a sub-set of subtasks.

The intention is to prevent the transition of the parent ticket if there is any subtask of that type with that particular value in the customfield_5555 that is not closed.

Regards

Enrique

Salih Tuç
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.
November 22, 2024

Yes, but I didn't mention that one :) Please take a look at the condition that I share and at the question (second one in question).

In the question, you are accessing the customfield through issueType, which is not correct. You are already checking if the issue is Sub-task, but you need to use directly "subtask.customfield..." in order to access the custom field value, instead of "subtask.issueType.customfield..."

Enrique November 25, 2024

Hi @Salih Tuç 

This is what I tried:

Original:

issue.subtasks.filter(subtask => subtask.issueType.name == 'Sub Test Execution' && subtask.issueType.customfield_5555.value == 'ABC' && subtask.status.name != 'Closed').length == 0

Following your recommendation I changed it to:

issue.subtasks.filter(subtask => subtask.issueType.name == 'Sub Test Execution' && subtask..customfield_5555.value == 'ABC' && subtask.status.name != 'Closed').length == 0

Since that did not work I tried replacing the customfield_5555 reference for the actual field name, which I needed to change because the name had spaces so I replaced " " for "_" underscores

issue.subtasks.filter(subtask => subtask.issueType.name == 'Sub Test Execution' && subtask..Sub_Test_Execution_type.value == 'ABC' && subtask.status.name != 'Closed').length == 0

None of this worked. I wonder if there anyway to debug this code, for example if "

 

subtask.issueType.customfield_5555.value" is an invalid syntax or I am referencing something that does not exist and that level, is there a log where this error is stored?

Regards

0 votes
Answer accepted
Nathan Phillips
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 25, 2024

Hello @Enrique,

Thank you for reaching out on the Atlassian Community. 

If you find that you are still facing issues, we actually recommend reaching out to ScriptRunner support directly.

Here is a link to ScriptRunner on our Atlassian Marketplace, and here is a direct link to their support page.

Thanks!

Enrique December 3, 2024

thank you.

0 votes
Maciej Dudziak _Forgappify_
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.
November 26, 2024

Hi @Enrique 

If you want to learn Jira expressions through examples, I can suggest trying the app our team developed —Workflow Building Blocks for Jira. It includes wizard-like validators, such as the Linked Issues Validator. With just a few clicks, you can create a validator based on a Jira expression.

Community_26.11.24_subtasks_validator.png

What might interest you is that each validator displays a Jira Expression Preview panel, which helps you learn the syntax. Later, you can build your own validator using our Jira Expression Validator, which features an autocomplete function to assist with syntax and custom field IDs.

I hope it will help.

Cheers

Enrique November 26, 2024

Thank you, I downloaded and I will look into it

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events