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
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Hi Team,
I want hide a text field depending on the value of select list field. written a below script but not getting expected output.
Can you please check and let me know where I am wrong:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
def textField = getFieldById("customfield_22695")
def selectList = getFieldById("customfield_22694")
def selectListValue = selectList.getValue()
if (selectListValue == "None")
{
textField.setHidden(true)
}
else
{
textField.setHidden(false)
}
Hi
NONE is not an actual value for the select list. It's only a place holder when no values are selected.
So you can do a simple groovy truthy check like this:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
def textField = getFieldById("customfield_22695")
def selectList = getFieldById("customfield_22694")
def selectListValue = selectList.value
if (selectListValue){
textField.setHidden(true)
} else {
textField.setHidden(false)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Peter,
If I want to modify my script to hide the field for the options called None and No.
The field should be visible for the value Yes, Can you check my below script is ok or need some modification:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
def textField = getFieldById("customfield_22695")
def selectList = getFieldById("customfield_22694")
def selectListValue = selectList.value
if (selectListValue == "None" || selectListValue == "No")
{
textField.setHidden(true)
}
else
{
textField.setHidden(false)
}
The above script is working for Yes and No value,, but not for None, kindly suggest teh correction.
Regards,
Neeta Jain
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
One of these should work:
if (!selectListValue || selectListValue == "No")
if (selectListValue == '' || selectListValue == "No")
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.
Where do i get the field id's for the custom fields that I have created ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
From the Custom Fields page, you can Edit a field or view the Field's configuration and you'll see the ID as part of the URL in either the edit or configure screen.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Peter, I got to know the custom field ID bia the URL . However, the automation doesn't seem to work. My objective is to Unhide "Impacted Service:" text field(custom) as soon as the user selects "Other" in the Affected Service field(custom). "Impacted Service :" field remains hidden on all the screens until then.
The following is my JSON code:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
def ImpactedServiceField = getFieldById("customfield_10069")
ImpactedServiceField.setHidden(false);
What am i missing here ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is Groovy code, not JSON.
You can't unhide a field that's hidden by the system.
Make sure your field is available for the current context, it has been added to the screen and is set to visible in the project field config.
Then and only then will you be able to set to hidden or visible at will using your scriptrunner/groovy code.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Alright, I have replaced the Groovy code with JSON (see below) and all the other pre-requisites are met like it has been added to the screen/context and is visible. How to make the field hidden now ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Behaviour on Server/DC doesn't support JSON. Only groovy.
Everything about this question was about Server/DC
If you're on Cloud, you'll be better off asking a brand new question and hopefully, someone else can help you. I have no experience with Scriptrunner on Cloud.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.