Hi, Newbie here. I have a basic workflow with custom fields. I would like to set some fields required based off values that the user enters in the same screen. I have script runner, but need help with how to code it. Any examples?
Hi Nagata,
You can add a behaviour.
import com.atlassian.jira.component.ComponentAccessor def jpField = getFieldByName("JIRA Project") def urlField = getFieldByName("GitLab URL") def aurlField = getFieldByName("Additional URL's / Notes") def NPField =getFieldByName("Name of Project") def PKField = getFieldByName("Project Key") //def JPFIeld = getFieldByName("JIRA Project") def fvField = getFieldById("fixVersions") def sField = getFieldByName("Sprint") def tField = getFieldById("timetracking_originalestimate") def rField = getFieldById("timetracking_remainingestimate") def SPField = getFieldByName("Story Points") def crField = getFieldById(getFieldChanged()) def selectedOption = crField.getValue() as String if ((selectedOption.contains("GIT Repositories"))) { urlField.setHidden(false) urlField.setRequired(true) aurlField.setHidden(false) aurlField.setRequired(true) jpField.setHidden(false) jpField.setRequired(true) NPField.setHidden(true) NPField.setRequired(false) PKField.setHidden(true) PKField.setRequired(false) fvField.setHidden(true) sField.setHidden(true) tField.setHidden(true) rField.setHidden(true) SPField.setHidden(true) } else { urlField.setHidden(true) urlField.setRequired(false) aurlField.setHidden(true) aurlField.setRequired(false) jpField.setHidden(false) jpField.setRequired(true) NPField.setHidden(true) NPField.setRequired(false) PKField.setHidden(true) PKField.setRequired(false) fvField.setHidden(true) sField.setHidden(true) tField.setHidden(true) rField.setHidden(true) SPField.setHidden(true)
Make sure to create a mapping between project and behaviour ID first and then add a field A base don which field B has to be changed or shown
In the above example, based on
def selectedOption = crField.getValue() as String , I am making other fields visible or hidden or required or not required.
Hope this helps
Regards
Chander
Thanks Chander. Can you help me with the getFieldById() function and the getFieldChanged() function?
In my example I have two fields. One is called CM_Environment and CM Pre-Production Environments Impacted. My use case is upon creation of a new issue, if the user selects the value "Pre-Production" in the CM_Environment field, I would like to have the CM Pre-Production Environments Impacted field required.
so I'm thinking I need to write:
def ppeField = getFieldbyName("CM Pre-Production Environment Impacted)
def cmeField = getFieldById(getFieldChanged())
def selected Option = cmeField.getValue() as String
if ((selected Option = "Pre-Production"))
{ppeField.setRequired(true) }
does that look right? I'm not sure how it nows that cmeField is the field "CM_Environment"
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.