My team wants to add a custom field that is read only until specific Components are selected. I have created a Behaviour on the field already. Currently the field is read only. I would like to create a custom script that can change the custom field to "writable" once the"Sys Admin" or "SysAdmin" component's are chosen. I've been banging my head on this for the last two days and I just feel lost now. Getting the list for the components seems to be the hardest part. Please help me out. (We have the server addition)
Hi @Terrell
I'm not a efficient coder, though below snippet will do the trick for you
import com.atlassian.jira.bc.project.component.ProjectComponentdef componentFF = getFieldById(fieldChanged)def field = getFieldByName("Field name to be read-only")field.setReadOnly(true) List <ProjectComponent> components = componentFF.getValue() as Listdef isThere = falsefor(c in components){ if(c.getName() == "Sys Admin" || c.getName() == "SysAdmin"){ isThere = true break }}if(isThere){ field.setReadOnly(false)}
Note: this behaviour should be added for Component/s field not for Custom field
BR,
Leo
Hey Leo, thanks for taking the time to reach out... I've implemented the code example you suggested and I'm not getting any errors but I am also not getting any results. I have the code executing as a server-side script. I am expecting the issue to attempt submission, but fail because I have set the "sysAdminCF" field as required. Is the logic incorrect?
Also, I'm not sure if I am using the correct component id as there are multiple id's within the man Div.
I'm not sure whether "components-textarea" is the correct one or not
you can use
def component = getFieldById(fieldChanged)
Ahh yes! I wasn't sure if "fieldChanged" was just used as a placeholder for the id of the component field or what. That explains why I wasn't getting any results. Thanks for your help, it works like a charm!
It looks like you're new here. Sign in or register to get started.