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.