You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
I am trying to execute a simple behaviour using Adaptavist ScriptRunner. On a workflow transition screen, I have 2 fields:
If the user selects "Training" in customfield_10907, then customfield_28501 should appear.
If the user selects any other value, then customfield_28501 should be hidden.
Here is my server-side script:
def CategoryField = getFieldById("customfield_10907")
def moreTrainingField = getFieldById("customfield_28501")
if (CategoryField.getValue() == "Training") {
moreTrainingField.setHidden(false)
} else {
moreTrainingField.setHidden(true)
}
The behaviour is not not working. customfield_28501 appears on the transition screen regardless of the selection in customfield_10907
Any suggestions on how to fix this so it will work?
Hi
I checked your code, modified a little bit, and it has to be work, I tested. If you set the proper project and issue type(s), and add the Category select field (10907) to the Fields, add the script like a Server-side script it has to be work.
If the fields appear together only in that transition screen you don't have to be do anything else. But is you use them together you should use an action, to avoid unexpected events.
/**
* Atlassian Community answer
* <a href="https://community.atlassian.com/t5/Jira-questions/Adaptavist-ScriptRunner-Behaviour-Hide-field-based-on-value-of/qaq-p/1453585" target="_blank">Adaptavist ScriptRunner Behaviour - Hide field based on value of other field</a>
* @author Tamás Baglyas - https://github.com/tbaglyas
* @version 1.0
* @since 2020-08-11
*/
if (getActionName().equals("Transition name where you want to use these behaviours.")) {
boolean hidden = !(getFieldById("customfield_10907")?.getValue()?.toString()?.equals("Training"));
getFieldById("customfield_28501").setHidden(hidden);
}
Cheers,
Tamás
Hi @Tamas Baglyas . Thanks for the reply. It is very close but doing the opposite of what I need. Currently, if the users selects Training, custom field 28501 is hidden. I want custom field 28501 visible only if user selects Training. Here is the script:
if (getActionName().equals("Validate Requirement")) {
boolean visible = getFieldById("customfield_10907")?.getValue()?.toString()?.equals("Training");
getFieldById("customfield_28501").setHidden(visible);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @[deleted] ,
Thanks, I modified my script based on your clarification. I think it is closer now.
Cheers,
Tamás
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Tamas Baglyas Hi!
I was looking for a solution and found your answer. Thank you! This works great!
I add this is code in BEHAVIOUR . It's worked !
Be sure to check the context. The code should be in the “field” tab, and not in the “Initialiser”"
boolean hidden = !(getFieldById("customfield_24511")?.getValue()?.toString()?.equals("Yes"))
getFieldById("customfield_24512").setHidden(hidden)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.