Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

I am also facing same issue 

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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

5 mobile apps for Jira Cloud to boost productivity

  It’s very important to have access to the workflow process from anywhere. Especially if you manage the work of others. There is no difference whether you’re out of office, or drive a ca...

225 views 2 5
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you