Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Script to hide Attachment field on Create/Edit based on another field selection

RakTeam February 15, 2019

I have written a behaviour that has a few fields hidden, but when a certain option is chosen in another field, those fields are shown.  How to I also write in to hide/show the Attachment field (While in create or edit mode)?  I have written what I though would work, but it is not hiding it.  Please see my script: 

 

{code}

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField

def customFieldManager = ComponentAccessor.customFieldManager
def optionsManager = ComponentAccessor.optionsManager

def campusTypeField = getFieldById("customfield_14126")
def learningObjField = getFieldById("customfield_16338")
def existingHCField = getFieldById("customfield_20091")
def attachWordField = getFieldById("customfield_20092")
def otherSupportField = getFieldById("customfield_20093")
def requestField = getFieldById("customfield_20094")
def releaseDateField = getFieldById("customfield_20095")
def earlyPublishField = getFieldById("customfield_20096")
def presentationAttachment = getFieldByName("Attachment")

 

if (campusTypeField.getValue() == "Help Center Article")

{
learningObjField.setHidden(false)
existingHCField.setHidden(false)
otherSupportField.setHidden(false)
requestField.setHidden(false)
releaseDateField.setHidden(false)
earlyPublishField.setHidden(false)
presentationAttachment.setHidden(false)

}

else
{
learningObjField.setHidden(true)
existingHCField.setHidden(true)
otherSupportField.setHidden(true)
requestField.setHidden(true)
releaseDateField.setHidden(true)
earlyPublishField.setHidden(true)
presentationAttachment.setHidden(true)
}

{code}

2 answers

2 votes
Vikrant Yadav
Community Champion
November 15, 2019

Hi 

 

I have fixed this issue.

We can't use system field byname, we can use system field by ID only

 

Attachment id is "attachment".

 

def Attachment = getFieldById("attachment")

 

Thanks

0 votes
Vikrant Yadav
Community Champion
November 13, 2019

I am also facing same issue 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events