How do we make certain fields hidden on changing issue type using behaviours ?

Hi @Jamie Echlin [Adaptavist],

                                             Can you help me with code where the field would be issue type and based on changes to issue type, i would like to make certain fields hidden or vsisible using Script Runner Behaviour plugin.

Writing Behaviour on a field Issue Type

import com.atlassian.jira.component.ComponentAccessor

def issueTypeField = getFieldById(getFieldChanged())
def jpField = getFieldByName("JIRA Project")
def urlField = getFieldByName("GitLab URL")
def aurlField = getFieldByName("Additional URL's / Notes")
def selectedOption = issueTypeField.getValue() as String

if (selectedOption == "Story")
{
    urlField.setHidden(false)
    urlField.setRequired(true)
    aurlField.setHidden(false)
    aurlField.setRequired(true)
    jpField.setHidden(false)
    jpField.setRequired(true)
  
}
else
{
    urlField.setHidden(true)
    urlField.setRequired(false)
    aurlField.setHidden(true)
    aurlField.setRequired(false)
    jpField.setHidden(true)
    jpField.setRequired(false)
}

 

What am i writing wrong in the code. please help me with this.

Regards

Chander Inguva

2 answers

Hi Chander

I think you need the getIssueContext() to retrieve the issue type and the project for example

def projectKey = getIssueContext().getProjectObject().getKey()
def issueTypeName = getIssueContext().getIssueTypeObject().getName()

Regards

Hey @Thanos Batagiannis [Adaptavist],

                                       That worked like magic. 

I have created an Initialiser like below

def projectKey = getIssueContext().getProjectObject().getKey()
def issueTypeName = getIssueContext().getIssueType().getName()
def WSField = getFieldByName("Wiki Space Name")
def SKField = getFieldByName("Space Key")
def SAField = getFieldByName("Space Administrators")
if (issueTypeName == "Wiki Space Request")
{
    WSField.setHidden(false)
    WSField.setRequired(true)
    SKField.setHidden(false)
    SKField.setRequired(true)
    SAField.setHidden(false)
    SAField.setRequired(true)
}
else
 {
    WSField.setHidden(true)
    WSField.setRequired(false)
    SKField.setHidden(true)
    SKField.setRequired(false)
    SAField.setHidden(true)
    SAField.setRequired(false)
}

Thank You

Chander Inguva

 

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

77 views 0 5
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you