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")))
(issue.issueType.name == 'Sub-task') && ((!cfValues['Product Type']*.value.contains("ECS")) || (!cfValues['Product Type']*.value.contains("Setup")))
@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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you @PD Sheehan . Its working as expected.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.