How to filter custom field values based on the selection of another field Follow
Answered
Let's assume that I have two custom fields: Country and City. I need to show cities only for the corresponding selected country:
How to implement this?
Please sign in to leave a comment.
First of all, let's create a field Country with its values:
and City:
As you can see, by default, all cities are shown independently of the selected country:
To filter these values, you can use the State-machines per Issue Type workflow rule. The example сode may seem complicated, but do not worry, we will try to simplify it.
For this, create a separate custom script and call it, for example, transitions-helper:
Then, create a separate State-machines per Issue Type rule and add a reference for transitions-helper:
Create a list of cities that should show for each country. Please note that all values should be the same as values in fields Country and City:
Then, specify the stateFieldName and typeFieldName properties:
Now, set the default state machine using the GenerateStateMachine method from our helper:
And finally, add alternative state machines:
Here is the complete code:
I hope it will be helpful!
Your example worked very well Oleg, thank you.
I have one issue though - After implementing this workflow, the "city" fieldvalues are all lowercase, and their colors aren't visible.
With workflow:
Without workflow:
Hello,
Please accept my apologies for the delayed response. I see that you created a separate State Machine per Issue type workflow forces lowercase thread, so let's continue it's discussing there.