Forums

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

Hide the workflow transition based on the custom field value

Lakshmi CH
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.
January 30, 2024

Hi Team,

I am trying to hide the workflow transition based on the custom field value.

I used "Simple scripted condition" with script runner for a transition, but it was showing when the "Product Type" is "ECS" or "Setup" values and hiding for other values, but I want reverse; it should be hidden when these values in "Product Type" field.

 

(issue.issueType.name == 'Sub-task') && ((cfValues['Product Type']*.value.contains("ECS")) || (cfValues['Product Type']*.value.contains("Setup")))
I tried with "Not," and then the transition shows for all values.
(issue.issueType.name == 'Sub-task') && ((!cfValues['Product Type']*.value.contains("ECS")) || (!cfValues['Product Type']*.value.contains("Setup")))

Is there any correct in my script? Can anyone please suggest one?

 

2 answers

1 accepted

0 votes
Answer accepted
PD Sheehan
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.
January 30, 2024

@Matt Doar's suggestion is a good one.

But I would also add that it helps to break down complex conditions with early return statements.

And remember that you must return true for the transition button to be visible.

if(issue.issueType.name != 'Sub-task') return false //never show the transition for non sub0tasks

def productTypes = cfValues['Product Type']*.value
def valuesToHideTransition = ['Setup', 'ECS']
if(valuesToHideTransition.intersect(productTypes)) return false //don't show if at least one select values is in valuesToHideTransition

return true //if not false return statements were evaluated, return true and show the transition

This is a bit more advanced by using the "intersect" method that returns all elements common between 2 arrays. If the intersect is an empty array ([]) that means the 2 list have nothing in common. The groovy truthiness on the if statment means that if the common element list includes at least 1 element, then one of those option was found and we can return false to hide the transition.

The long-form way to do this would be:

if(productTypes.any{ it in valuesToHideTransition}) return false

 

Lakshmi CH
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.
January 31, 2024

Hi @PD Sheehan ,

 Thank you for the quick response. Its seems not working because, we have three subtasks, and using same workflow. Sub-task, OB Task, and SN Task.

The code is working for Sub-task, its not showing the "Waiting for Build" transition when Product Type is ECS or Setup, and showing for all other values on sub-task (This is GOOD),

but, for other sub-task (OB Task and SN Task) issue types, there are no restrictions, the transition should show for all Product Values, but here, the transition is not showing.

product.png

PD Sheehan
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.
January 31, 2024

Then change that first line from

if(issue.issueType.name != 'Sub-task') return false //never show the transition for non sub-tasks

To

if(issue.issueType.name != 'Sub-task') return true//alway show the transition for non Sub-tasks
Lakshmi CH
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.
January 31, 2024

Thank you @PD Sheehan . Its working as expected. 

0 votes
Matt Doar
Community Champion
January 30, 2024

Make life easier for yourself by using intermediate boolean variables such as

isSubtask = (issue.issueType.name == 'Sub-task')

then the logic will be easier to read. Document exactly when the expression should return true. Test the logic is correct outside the condition code to make the development cycle shorter.

Suggest an answer

Log in or Sign up to answer